import { logger } from "../../utils/logger.js";
let machineLabelProviders = {};
export function setMachineLabelProviders(providers) {
    machineLabelProviders = providers;
}
export async function machineLabelRoutes(app) {
    app.get("/machine/label", async (_request, reply) => {
        const label = machineLabelProviders.getLabel?.() ?? null;
        return reply.status(200).send({ label });
    });
    app.post("/machine/label", async (request, reply) => {
        const { label } = request.body;
        if (typeof label !== "string" || label.trim().length === 0) {
            return reply.status(400).send({ error: "Label must be a non-empty string" });
        }
        const trimmed = label.trim();
        if (!machineLabelProviders.setLabel) {
            return reply.status(503).send({ error: "Daemon not fully initialized" });
        }
        try {
            await machineLabelProviders.setLabel(trimmed);
            logger.info(`Machine label updated: ${trimmed}`);
            return reply.status(200).send({ label: trimmed });
        }
        catch (err) {
            const message = err instanceof Error ? err.message : String(err);
            logger.error(`Failed to set machine label: ${message}`);
            return reply.status(500).send({ error: message });
        }
    });
}
//# sourceMappingURL=machine-label.js.map