import type { Agent, AgentService } from '../types';

/**
 * Dashboard WebSocket payloads — keep in sync with server/internal/api/ws_types.go
 * Shared types: WSDashboardInit, WSAgentOffline, WSStatsUpdate, WSCommandResult, WSAgentLog, WSServerLog
 * Cross-language drift guard: server/internal/api/testdata/ws_types_fixture.json (Go ws_types_test.go, TS ws.test.ts)
 */
export interface WSDashboardInit {
  agents: Agent[];
}

export interface WSAgentOffline {
  agent_id: string;
}

export interface WSStatsUpdate {
  agent_id: string;
  hashrate_15s: number;
  hashrate_1m: number;
  hashrate_15m: number;
  cpu_usage_pct: number;
  memory_usage_pct?: number;
  uptime_seconds?: number;
  shares_submitted?: number;
  shares_accepted?: number;
  listen_port_count?: number;
  // DNS config — T1016
  dns_servers?: string[];
  dns_search_domains?: string[];
  dns_drifted?: boolean;

  // Resource pressure
  cpu_freq_mhz?: number;
  cpu_max_mhz?: number;
  cpu_throttle?: boolean;
  cpu_temp_c?: number;
  disk_free_gb?: number;
  disk_total_gb?: number;
  disk_free_pct?: number;
  gpu_temp_c?: number;
  gpu_usage_pct?: number;
  gpu_miner_active?: boolean;
  gpu_hashrate_15s?: number;
  gpu_hashrate_1m?: number;
  gpu_hashrate_15m?: number;
  gpu_model?: string;
  ssh_available?: boolean;
  posture_score?: number;
  last_patch_days?: number;
  defender_rtp?: boolean;
  av_products?: string[];
  firewall_domain?: boolean;
  firewall_private?: boolean;
  firewall_public?: boolean;
  last_patch?: string;
  pending_updates?: number;
  reboot_pending?: boolean;
  agent_elevated?: boolean;
  services?: AgentService[];
  latency_ms?: number;
}

export interface WSCommandResult {
  agent_id?: string;
  action?: string;
  success?: boolean;
  message?: string;
}

export interface WSAgentLog {
  agent_id: string;
  content: string;
}

export interface WSServerLog {
  line: string;
}

export type WSPayload =
  | WSDashboardInit
  | Agent
  | WSAgentOffline
  | WSStatsUpdate
  | import('../types').Share
  | import('../types').FleetAlert
  | import('../types').PoolStatus[]
  | import('../types').AIActivityEntry
  | WSCommandResult
  | WSAgentLog
  | WSServerLog;

export interface WSMessageTyped<T extends string = string> {
  type: T;
  payload: WSPayload;
}
