/**
 * Domain, DNS, and certificate data shapes for Onebox
 */

export interface IDomain {
  id?: number;
  domain: string;
  dnsProvider: 'cloudflare' | 'manual' | 'dcrouter' | null;
  cloudflareZoneId?: string;
  isObsolete: boolean;
  defaultWildcard: boolean;
  createdAt: number;
  updatedAt: number;
}

export interface ICertificate {
  id?: number;
  domainId: number;
  certDomain: string;
  isWildcard: boolean;
  certPem: string;
  keyPem: string;
  fullchainPem: string;
  expiryDate: number;
  issuer: string;
  isValid: boolean;
  createdAt: number;
  updatedAt: number;
}

export interface ICertRequirement {
  id?: number;
  domainId: number;
  serviceId: number;
  subdomain: string;
  status: 'pending' | 'active' | 'renewing' | 'failed';
  certificateId?: number;
  createdAt: number;
  updatedAt: number;
}

export interface IDomainDetail {
  domain: IDomain;
  certificates: ICertificate[];
  requirements: ICertRequirement[];
  serviceCount: number;
  certificateStatus: 'valid' | 'expiring-soon' | 'expired' | 'pending' | 'none';
  daysRemaining: number | null;
}

export interface IDnsRecord {
  id?: number;
  domain: string;
  type: 'A' | 'AAAA' | 'CNAME';
  value: string;
  cloudflareID?: string;
  createdAt: number;
  updatedAt: number;
}

export interface IGatewayDomain {
  id?: string;
  name: string;
  source?: 'dcrouter' | 'provider';
  authoritative?: boolean;
  providerId?: string;
  serviceCount?: number;
  managePath?: string;
  manageUrl?: string;
  capabilities?: {
    canCreateSubdomains: boolean;
    canManageDnsRecords: boolean;
    canIssueCertificates: boolean;
    canHostEmail: boolean;
  };
}

export interface IGatewayDnsRecord {
  id: string;
  domainId: string;
  domainName?: string;
  name: string;
  type: string;
  value: string;
  ttl: number;
  source: string;
  status: 'active' | 'missing';
  gatewayClientType: 'onebox' | 'cloudly' | 'custom';
  gatewayClientId: string;
  appId: string;
  hostname: string;
  routeId?: string;
  serviceName?: string;
  managePath?: string;
  manageUrl?: string;
}
