import Fastify from "fastify";
import { CONTROL_PLANE_HOST, CONTROL_PLANE_PORT } from "@pocketcoder/shared";
import { logger } from "../utils/logger.js";
import { healthRoutes } from "./routes/health.js";
import { machineLabelRoutes } from "./routes/machine-label.js";
import { reRegisterRoutes } from "./routes/re-register.js";
import { statusRoutes } from "./routes/status.js";
import { projectSyncRoutes } from "./routes/project-sync.js";
import { stopRoutes } from "./routes/stop.js";
export function createControlPlane(options) {
    const host = options?.host ?? CONTROL_PLANE_HOST;
    const port = options?.port ?? CONTROL_PLANE_PORT;
    const app = Fastify({ logger: false });
    let currentAddress = null;
    // Register routes
    void app.register(healthRoutes);
    void app.register(machineLabelRoutes);
    void app.register(projectSyncRoutes);
    void app.register(reRegisterRoutes);
    void app.register(statusRoutes);
    void app.register(stopRoutes);
    return {
        async start() {
            const address = await app.listen({ host, port });
            currentAddress = address;
            logger.info(`Control plane listening on ${address}`);
            return address;
        },
        async stop() {
            logger.info("Control plane shutting down");
            await app.close();
            currentAddress = null;
        },
        get address() {
            return currentAddress;
        },
    };
}
//# sourceMappingURL=server.js.map