import { apiRequest, type ApiOutcome } from './client' import type { RunOutcome } from './apps' /* Zones across the servers, behind a hub (hub/zones-sync.ts): the merged list, copying a zone to other servers, and making a zone a Secondary of another server's Primary. */ export interface ZoneCell { state: 'present' | 'absent' | 'unknown' type?: string serial?: number | null disabled?: boolean dnssec?: string lastModified?: string } export type RowStatus = 'same' | 'serial-differs' | 'type-differs' | 'only-on' | 'missing-on' | 'unknown' export interface MatrixZone { name: string cells: Record status: RowStatus onlyOn?: string missingOn?: string[] note?: 'primary-secondary' | 'secondary-behind' } export interface ZonesMatrixData { servers: { id: string; ok: boolean; writable: boolean; host: string; error?: string }[] zones: MatrixZone[] } export const getZonesMatrix = (token: string | null): Promise> => apiRequest('hub/zones/matrix', { token }) export interface CopyTargetPreview { server: string ok: boolean error?: string writable: boolean exists: boolean type?: string serial?: number | null needsOverwrite: boolean } export interface CopyPreview { zone: string source: { server: string; type: string; serial: number | null; records: number; bytes: number } warnings: string[] targets: CopyTargetPreview[] } export const previewZoneCopy = (token: string | null, source: string, zone: string, targets: string[]): Promise> => apiRequest('hub/zones/copy/preview', { token, method: 'POST', body: { source, zone, targets: targets.join(',') } }) export const copyZone = (token: string | null, source: string, zone: string, targets: string[], overwrite: string[]): Promise => apiRequest('hub/zones/copy', { token, method: 'POST', body: { source, zone, targets: targets.join(','), overwrite: overwrite.join(',') } }) export interface SecondaryInput { source: string target: string zone: string primaryAddress: string targetAddress: string tsigKeyName: string } export interface SecondaryPreview { zone: string source: string target: string warnings: string[] steps: { server: string; role: 'source' | 'target'; summary: string; changes: boolean }[] } export const previewSecondary = (token: string | null, input: SecondaryInput): Promise> => apiRequest('hub/zones/secondary/preview', { token, method: 'POST', body: { ...input } }) export const makeSecondary = (token: string | null, input: SecondaryInput): Promise => apiRequest('hub/zones/secondary', { token, method: 'POST', body: { ...input } })