import { handleHeapzRequest } from "../../services/heapz.js";
import { HttpService } from "../../services/http-service.js";
import { handleStatzRequest } from "../../services/statz.js";
import { installWebSocketHandoff, } from "../../types/websocket-handoff.js";
import { handleAnalyzeQueryRequest, setCors } from "../../services/analyze.js";
export class ZeroDispatcher extends HttpService {
    id = 'zero-dispatcher';
    #getWorker;
    constructor(config, lc, opts, getWorker) {
        super(`zero-dispatcher`, lc, opts, fastify => {
            fastify.get('/statz', (req, res) => handleStatzRequest(lc, config, req, res));
            fastify.get('/heapz', (req, res) => handleHeapzRequest(lc, config, req, res));
            fastify.options('/analyze-queryz', (_req, res) => setCors(res)
                .header('Access-Control-Max-Age', '86400')
                .status(204)
                .send());
            fastify.post('/analyze-queryz', (req, res) => handleAnalyzeQueryRequest(lc, config, req, res));
            installWebSocketHandoff(lc, this.#handoff, fastify.server);
        });
        this.#getWorker = getWorker;
    }
    #handoff = (_req, dispatch, onError) => {
        void this.#getWorker().then(sender => dispatch({ payload: 'unused', sender }), onError);
    };
}
//# sourceMappingURL=zero-dispatcher.js.map