/** Local network diagnostics (runs on the desktop, not over SSH). */
import { call, subscribe } from "../transport";
import type { Payload, Result } from "../types";

export type ExportFormat = "json" | "csv" | "txt";

export const diagnostics = Object.freeze({
  resolve: (options: Payload) => call<Result<unknown>>("core_diagnostics_resolve", "diagnostics:resolve", options),
  start: (options: Payload) => call<Result<{ id: string; report: unknown }>>("core_diagnostics_start", "diagnostics:start", options),
  cancel: (id: string, tool?: string) => call<Result<unknown>>("core_diagnostics_cancel", "diagnostics:cancel", { id, tool }),
  get: (id: string) => call<Result<unknown>>("core_diagnostics_get", "diagnostics:get", { id }),
  history: () => call<Result<unknown[]>>("core_diagnostics_history", "diagnostics:history"),
  removeHistory: (id?: string) => call<Result<unknown>>("core_diagnostics_remove_history", "diagnostics:removeHistory", { id }),
  export: (id: string, format: ExportFormat) => call<Result<{ canceled: boolean }>>("core_diagnostics_export", "diagnostics:export", { id, format }),
  copy: (id: string, format: ExportFormat = "txt") => call<Result<{ copied: true }>>("core_diagnostics_copy", "diagnostics:copy", { id, format }),
  import: () => call<Result<{ canceled?: boolean; id?: string }>>("core_diagnostics_import", "diagnostics:import"),
  onProgress: (callback: (event: Payload) => void) => subscribe("diagnostics:progress", callback)
});
