import type { Client } from 'ssh2'
import { execCommand } from './common.js'

export async function collectSystemMetrics(
  client: Client,
): Promise<{ hostname: string | null; kernel: string | null; os: string | null }> {
  try {
    const [hostnameOut, kernelOut, osOut] = await Promise.all([
      execCommand(client, 'hostname'),
      execCommand(client, 'uname -r'),
      execCommand(client, "cat /etc/os-release | grep '^PRETTY_NAME=' | cut -d'\"' -f2"),
    ])
    return {
      hostname: hostnameOut.stdout.trim() || null,
      kernel: kernelOut.stdout.trim() || null,
      os: osOut.stdout.trim() || null,
    }
  } catch {
    return { hostname: null, kernel: null, os: null }
  }
}
