/**
 * AWS Route 53 DNS sync — shared type definitions.
 * API-response shapes (camelCase) — route handlers transform snake_case
 * Postgres rows into these manually (no ORM, per CLAUDE.md).
 */

// ============================================================================
// Zone / Record mirror types
// ============================================================================

export interface Route53Zone {
  id: string;
  name: string;
  comment: string | null;
  privateZone: boolean;
  recordCount: number;
  authoritativeNameServers: string[] | null;
  syncedAt: string;
  isDeleted: boolean;
}

export interface Route53RecordValue {
  value: string;
}

export interface Route53Record {
  recordKey: string;
  zoneId: string;
  name: string;
  type: string;
  setIdentifier: string | null;
  ttl: number | null;
  resourceRecords: Route53RecordValue[] | null;
  aliasTarget: Record<string, unknown> | null;
  syncedAt: string;
  isDeleted: boolean;
}

// ============================================================================
// Change ledger / audit log types
// ============================================================================

export type Route53HistorySource = 'pulse_crud' | 'sync_detected_drift';

export interface Route53RecordHistory {
  id: string;
  zoneId: string;
  recordKey: string;
  recordName: string;
  recordType: string;
  changeAction: 'create' | 'update' | 'delete';
  beforeValue: Record<string, unknown> | null;
  afterValue: Record<string, unknown> | null;
  source: Route53HistorySource;
  changedByUserId: string | null;
  changedByEmail: string | null;
  changedAt: string;
}

export type Route53AuditStatus = 'pending' | 'committed' | 'failed';

export interface Route53AuditLog {
  id: string;
  operation: 'create' | 'update' | 'delete' | 'sync';
  zoneId: string | null;
  recordKey: string | null;
  recordName: string | null;
  recordType: string | null;
  beforeValue: Record<string, unknown> | null;
  afterValue: Record<string, unknown> | null;
  performedByUserId: string | null;
  performedByEmail: string | null;
  performedAt: string;
  completedAt: string | null;
  status: Route53AuditStatus;
  awsChangeId: string | null;
  awsChangeStatus: string | null;
  errorMessage: string | null;
}

// ============================================================================
// Writable record types (D-01)
// ============================================================================

export type Route53WritableType = 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT' | 'SRV';

// ============================================================================
// Sync result
// ============================================================================

export interface Route53SyncResult {
  syncId: string;
  syncType: string;
  status: string;
  startedAt: string;
  completedAt: string | null;
  duration: number | null;
  entities: Record<string, unknown>;
  errors: string[];
}
