import type { Client } from 'ssh2'
import { collectCpuMetrics } from './cpu.js'
import { collectMemoryMetrics } from './memory.js'
import { collectDiskMetrics } from './disk.js'
import { collectUptimeMetrics } from './uptime.js'
import { collectNetworkMetrics } from './network.js'
import { collectSystemMetrics } from './system.js'
import { collectProcessesMetrics } from './processes.js'
import { collectPortsMetrics } from './ports.js'
import { collectFirewallMetrics } from './firewall.js'
import { collectLoginStats } from './login-stats.js'

/**
 * Collectors run sequentially rather than via Promise.all: each one opens
 * 1-3 SSH exec channels, and running all ~10 collectors concurrently can open
 * 15-20 channels at once, which exceeds OpenSSH's default `MaxSessions 10`
 * and silently starves whichever collectors lose the race.
 */
export async function collectHostMetrics(client: Client) {
  const cpu = await collectCpuMetrics(client)
  const memory = await collectMemoryMetrics(client)
  const disk = await collectDiskMetrics(client)
  const uptime = await collectUptimeMetrics(client)
  const network = await collectNetworkMetrics(client)
  const system = await collectSystemMetrics(client)
  const processes = await collectProcessesMetrics(client)
  const ports = await collectPortsMetrics(client)
  const firewall = await collectFirewallMetrics(client)
  const loginStats = await collectLoginStats(client)
  return { cpu, memory, disk, uptime, network, system, processes, ports, firewall, loginStats }
}
