import type { OverlayPeerRef } from "./traffic-flow-map-exporter.js"

export interface ExporterMapPayload {
  overlayPrefix: string
  byTunnelIp: Array<[string, number]>
  peers: OverlayPeerRef[]
  hostIps: Array<[string, number]>
}

export interface CollectorStartPayload {
  dbPath: string
  listenHost: string
  listenPort: number
  topN: number
  retentionHours: number
  exporterMap: ExporterMapPayload
}

export interface CollectorHeartbeat {
  bound: boolean
  address: string | null
  packetsReceived: number
  lastExporterIp: string | null
  lastError: string
  lastDatagramAt: string | null
  pendingSize: number
  dropped: number
  rowsStored: number
  workerAlive: boolean
  rings: Array<{ key: string; inBps: number[]; outBps: number[] }>
}

export type MainToWorker =
  | { type: "start"; payload: CollectorStartPayload }
  | { type: "stop" }
  | { type: "updateExporterMap"; payload: ExporterMapPayload }
  | { type: "updateSettings"; payload: { topN: number; retentionHours: number } }

export type WorkerToMain =
  | { type: "heartbeat"; payload: CollectorHeartbeat }
  | { type: "error"; payload: { message: string } }
