export interface WebSocketMessage {
  type: string;
  data: any;
  timestamp?: number;
  client_id?: string;
  message_id?: string;
}

export interface ConnectionInfo {
  client_id: string;
  static_id: string;
  ip_address: string;
  room: string;
  user_id: string;
  connected_at: number;
  id_type: string;
}

export interface ClientInfo {
  id: string;
  static_id: string;
  ip_address: string;
  user_id: string;
  room: string;
  connected_at: number;
  last_ping: number;
  is_active?: boolean;
}

export interface OnlineUser {
  client_id: string;
  static_id: string;
  user_id: string;
  room: string;
  ip_address: string;
  connected_at: number;
  last_ping: number;
}

export interface ConnectionStats {
  connected_clients: number;
  unique_ips: number;
  static_clients: number;
  active_rooms: number;
  ip_distribution: Record<string, number>;
  room_distribution: Record<string, number>;
  message_queue_size: number;
  queue_workers: number;
  uptime: number;
  timestamp: number;
}

export interface SystemHealth {
  databases: any;
  available_dbs: string[];
  websocket_status: string;
  uptime_seconds: number;
}

export interface PerformanceMetrics {
  messages_per_second: number;
  average_latency_ms: number;
  error_rate_percent: number;
  memory_usage_bytes: number;
}

export interface MonitoringData {
  stats: ConnectionStats;
  recent_activity: ActivityLog[];
  system_health: SystemHealth;
  performance: PerformanceMetrics;
}

export interface ActivityLog {
  timestamp: number;
  event: string;
  client_id: string;
  details: string;
}

export interface MessageHistory {
  timestamp: Date;
  type: string;
  data: any;
  messageId?: string;
  size: number;
  icon?: string;
  timeString?: string;
}

export interface ConnectionState {
  isConnected: boolean;
  isConnecting: boolean;
  connectionStatus: "disconnected" | "connecting" | "connected" | "error";
  clientId: string | null;
  staticId: string | null;
  currentRoom: string | null;
  userId: string;
  ipAddress: string | null;
  connectionStartTime: number | null;
  lastPingTime: number | null;
  connectionLatency: number;
  connectionHealth: "poor" | "warning" | "good" | "excellent";
  reconnectAttempts: number;
  messagesReceived: number;
  messagesSent: number;
  uptime: string;
}

export interface WebSocketConfig {
  wsUrl: string;
  userId: string;
  room: string;
  staticId?: string;
  useIPBasedId?: boolean;
  autoReconnect: boolean;
  heartbeatEnabled: boolean;
  maxReconnectAttempts: number;
  reconnectDelay: number;
  maxReconnectDelay: number;
  heartbeatInterval: number;
  heartbeatTimeout: number;
  maxMissedHeartbeats: number;
  maxMessages: number;
  messageWarningThreshold: number;
  actionThrottle: number;
}

export type MessageType =
  | "welcome"
  | "broadcast"
  | "direct_message"
  | "room_message"
  | "ping"
  | "pong"
  | "heartbeat"
  | "heartbeat_ack"
  | "connection_test"
  | "connection_test_result"
  | "get_online_users"
  | "online_users"
  | "get_server_info"
  | "server_info"
  | "error"
  | "message_received"
  | "broadcast_sent"
  | "direct_message_sent"
  | "room_message_sent"
  | "db_insert"
  | "db_query"
  | "db_custom_query"
  | "query_result"
  | "admin_kick_client"
  | "admin_kill_server"
  | "get_server_stats"
  | "get_system_health"
  | "admin_clear_logs"
  | "get_stats"
  | "get_room_info"
  | "join_room"
  | "leave_room"
  | "database_change"
  | "data_stream"
  | "server_heartbeat"
  | "system_status"
  | "clients_by_ip"
  | "client_info"
  | "get_clients_by_ip"
  | "get_client_info"
  | "health_check"
  | "database_list"
  | "connection_stats"
  | "trigger_notification"
  | "notification_sent"
  | "API_TEST"
  | "manual_test"
  | "retribusi_created"
  | "retribusi_updated"
  | "retribusi_deleted"
  | "peserta_changes"
  | "retribusi_changes"
  | "system_changes";
