export interface ServerConfig {
  id: string;
  name: string;
  url: string;
  enabled: boolean;
}

export interface CPUMetrics {
  model: string;
  cores: number;
  usagePercent: number;
  loadAverages?: number[];
  temperature?: number;
  perCoreUsage?: CoreUsage[];
}

export interface CoreUsage {
  core: number;
  percent: number;
}

export interface MemoryMetrics {
  totalBytes: number;
  usedBytes: number;
  freeBytes: number;
  usedPercent: number;
  /** 交换分区 / swap 总量（字节），由新版采集端上报 */
  swapTotalBytes?: number;
  swapUsedBytes?: number;
  swapFreeBytes?: number;
  swapUsedPercent?: number;
  /** file / partition / zram 等，来自 /proc/swaps；「无」表示未配置 swap */
  swapType?: string;
}

export interface StorageMetrics {
  mount: string;
  totalBytes: number;
  usedBytes: number;
  freeBytes: number;
  usedPercent: number;
}

export interface GPUMetrics {
  name: string;
  memoryTotalMB: number;
  memoryUsedMB: number;
  utilizationPercent: number;
  temperature?: number;
  status: string;
}

export interface NetworkInterface {
  name: string;
  ipAddress: string;
  macAddress: string;
  rxBytes: number;
  txBytes: number;
  rxSpeed: number;
  txSpeed: number;
}

export interface SystemStats {
  processCount: number;
  /** 当前登录会话数（who 行数）；新版采集端上报 */
  loggedInUsers?: number;
  /** TCP 套接字数（/proc/net/tcp + tcp6，含监听与各状态）；新版采集端上报 */
  tcpConnections?: number;
  packageCount: number;
  packageManager: string;
  temperature?: number;
  diskReadSpeed: number;
  diskWriteSpeed: number;
  networkRxSpeed?: number;
  networkTxSpeed?: number;
  topProcesses: ProcessInfo[];
  dockerStats: DockerStats;
  systemLogs?: string[];
}

export interface ProcessInfo {
  pid: number;
  name: string;
  cpu: number;
  memory: number;
  memoryMB: number;
  command: string;
}

export interface DockerStats {
  available: boolean;
  version?: string;
  running: number;
  stopped: number;
  imageCount: number;
  runningNames?: string[];
  stoppedNames?: string[];
  imageNames?: string[];
}

export interface OSInfo {
  kernel: string;
  distro: string;
  architecture: string;
}

export interface LatencyInfo {
  clientToServer: number;
  external: {
    'baidu.com'?: string;
    'google.com'?: string;
    'github.com'?: string;
  };
}

export interface ServerMetrics {
  hostname: string;
  timestamp: string;
  cpu: CPUMetrics;
  memory: MemoryMetrics;
  storage: StorageMetrics[];
  gpu: GPUMetrics[];
  network: NetworkInterface[];
  system: SystemStats;
  os: OSInfo;
  uptimeSeconds: number;
  latency?: LatencyInfo;
}

export interface ServerStatus {
  serverId: string;
  online: boolean;
  metrics?: ServerMetrics;
  error?: string;
  lastUpdate: number;
}
