"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const droid_dashboard_service_1 = require("../services/droid-dashboard-service");
const router = (0, express_1.Router)();
/**
 * GET /api/droid/diagnostics
 * Dashboard-ready Droid installation + BYOK configuration diagnostics.
 */
router.get('/diagnostics', async (_req, res) => {
    try {
        res.json(await (0, droid_dashboard_service_1.getDroidDashboardDiagnostics)());
    }
    catch (error) {
        res.status(500).json({ error: error.message });
    }
});
/**
 * GET /api/droid/settings/raw
 * Raw ~/.factory/settings.json payload for editor.
 */
router.get('/settings/raw', async (_req, res) => {
    try {
        res.json(await (0, droid_dashboard_service_1.getDroidRawSettings)());
    }
    catch (error) {
        res.status(500).json({ error: error.message });
    }
});
/**
 * PUT /api/droid/settings/raw
 * Save raw ~/.factory/settings.json payload from dashboard editor.
 */
router.put('/settings/raw', async (req, res) => {
    try {
        const { rawText, expectedMtime } = req.body ?? {};
        if (typeof rawText !== 'string') {
            res.status(400).json({ error: 'rawText must be a string.' });
            return;
        }
        if (expectedMtime !== undefined &&
            (typeof expectedMtime !== 'number' || !Number.isFinite(expectedMtime))) {
            res.status(400).json({ error: 'expectedMtime must be a finite number when provided.' });
            return;
        }
        res.json(await (0, droid_dashboard_service_1.saveDroidRawSettings)({ rawText, expectedMtime }));
    }
    catch (error) {
        if (error instanceof droid_dashboard_service_1.DroidRawSettingsValidationError) {
            res.status(400).json({ error: error.message });
            return;
        }
        if (error instanceof droid_dashboard_service_1.DroidRawSettingsConflictError) {
            res.status(409).json({ error: error.message, mtime: error.mtime });
            return;
        }
        res.status(500).json({ error: error.message });
    }
});
exports.default = router;
//# sourceMappingURL=droid-routes.js.map