import { createServer } from "node:http";
export function startHealthServer(port, signals) {
    const server = createServer((req, res) => {
        if (req.url === "/healthz") {
            const ok = signals.listenerConnected();
            res.statusCode = ok ? 200 : 503;
            res.end(ok ? "ok" : "listener disconnected");
            return;
        }
        if (req.url === "/readyz") {
            const ok = signals.startupReconcileDone();
            res.statusCode = ok ? 200 : 503;
            res.end(ok ? "ok" : "startup reconcile pending");
            return;
        }
        res.statusCode = 404;
        res.end();
    });
    server.listen(port, () => {
        console.info(`[health] listening on :${port}`);
    });
    return server;
}
