import type {
  ClusterId,
  ConnectionId,
  CredentialReferenceId,
  MachineEnrollmentId,
  MachineId,
  OperationId,
} from "./ids.js";

export type MachineEnrollmentPhase =
  | "requested"
  | "preflight"
  | "awaiting-confirmation"
  | "installing"
  | "joining"
  | "verifying"
  | "discovering"
  | "completed"
  | "failed";

export interface MachineEnrollmentRequest {
  readonly clusterId: ClusterId;
  readonly name: string;
  readonly address: string;
  readonly sshUser: string;
  readonly sshConnectionId: ConnectionId;
  readonly sshCredentialReferenceId: CredentialReferenceId;
  readonly labels?: Readonly<Record<string, string>>;
}

export interface MachinePreflightReport {
  readonly reachable: boolean;
  readonly hostname: string;
  readonly osId: string;
  readonly osVersion?: string;
  readonly architecture: string;
  readonly cpuCount: number;
  readonly memoryBytes: number;
  readonly diskFreeBytes: number;
  readonly hasK3s: boolean;
  readonly k3sRole?: "server" | "agent";
  readonly k3sVersion?: string;
  readonly k3sServerUrl?: string;
  readonly kubernetesNodeName?: string;
  readonly state: "clean" | "already-enrolled" | "partial" | "foreign" | "unsupported";
  readonly blockingReasons: readonly string[];
  readonly observedAt: string;
  readonly fingerprint: string;
}

export interface MachineEnrollmentReceipt {
  readonly id: MachineEnrollmentId;
  readonly operationId: OperationId;
  readonly machineId: MachineId;
  readonly phase: MachineEnrollmentPhase;
  readonly preflight?: MachinePreflightReport;
  readonly failureReason?: string;
  readonly updatedAt: string;
}
