/**
 * Shared TypeScript types for SSH UI components. These mirror the wire format
 * returned by src/bridge/ssh-api.ts (`presentConnection`, `presentGrant`,
 * `presentAuditRow`) — kept here so panels under userfolder/ and settings/
 * can share a single source of truth.
 */

export type HostKeyPendingSource = 'tofu_record' | 'mismatch';

export interface SshConnection {
  id: string;
  ownerId: string | null;
  label: string;
  host: string;
  port: number;
  username: string;
  keyVersion: number;
  keyFingerprint: string | null;
  hostKeyType: string | null;
  hostKeyFingerprint: string | null;
  hostKeyRecordedAt: string | null;
  hostKeyVerifiedAt: string | null;
  hostKeyPending: boolean;
  hostKeyPendingFingerprint: string | null;
  hostKeyPendingSource: HostKeyPendingSource | null;
  commandDenyPatterns: string | null;
  commandAllowPatterns: string | null;
  remotePathPrefix: string;
  allowRemoteUnrestricted: boolean;
  allowPrivateAddresses: boolean;
  enabled: boolean;
  disabledByAdmin: boolean;
  disabledByAdminReason: string | null;
  disabledByAdminAt: string | null;
  disabledByAdminUserId: string | null;
  createdAt: string;
  updatedAt: string;
}

export type SshGrantSubjectType = 'user' | 'org';

export interface SshGrant {
  id: string;
  connectionId: string;
  subjectType: SshGrantSubjectType;
  subjectId: string;
  pieceName: string | null;
  appliesToAllPieces: boolean;
  grantedByUserId: string;
  reason: string;
  expiresAt: string | null;
  createdAt: string;
}

export interface SshAuditRow {
  id: number;
  action: string;
  entityType: string | null;
  entityId: string | null;
  connectionId: string | null;
  ownerId: string | null;
  actingUserId: string | null;
  jobId: string | null;
  pieceName: string | null;
  outcome: string;
  reason: string | null;
  detail: unknown;
  startedAt: string;
  completedAt: string | null;
}

export type TestVerdict = 'first_observe' | 'mismatch' | 'pass' | 'alg_not_allowed';

export interface TestResponse {
  verdict: TestVerdict;
  fingerprint: string;
  hostKeyType: string;
  pendingToken: string | null;
}

export interface MaintenanceSnapshot {
  active: boolean;
  reason?: string;
  jobId?: string;
  enteredAt?: string;
}
