"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createControlsRouter = void 0;
const express_1 = require("express");
const logger_1 = require("../utils/logger");
const InterfaceGenerationService_1 = require("../services/InterfaceGenerationService");
const log = (0, logger_1.createLogger)('ControlsRoutes');
/**
 * Routes for Generative Editor Interfaces. Generation only — promotion (Phase 3)
 * reuses the existing apply pipeline, so there is no `/promote` route here.
 * See docs/generative-editor-interfaces.md.
 */
const createControlsRouter = () => {
    const router = (0, express_1.Router)();
    router.post('/controls/generate', async (req, res) => {
        try {
            const body = req.body ?? {};
            const description = String(body.description ?? '').trim();
            if (!description) {
                return res.status(400).json({ error: 'description is required' });
            }
            const params = {
                description,
                existingSectionTitles: Array.isArray(body.existingSectionTitles)
                    ? body.existingSectionTitles.map(String)
                    : undefined,
                elementSummary: typeof body.elementSummary === 'string'
                    ? body.elementSummary
                    : undefined,
                tokenSummary: typeof body.tokenSummary === 'string' ? body.tokenSummary : undefined,
                model: typeof body.model === 'string' && body.model.trim().length > 0
                    ? body.model.trim()
                    : undefined,
            };
            const sections = await (0, InterfaceGenerationService_1.generateEditorInterface)(params);
            return res.json({ sections });
        }
        catch (error) {
            log.error('Interface generation failed', error);
            return res.status(500).json({
                error: error instanceof Error
                    ? error.message
                    : 'Interface generation failed',
            });
        }
    });
    return router;
};
exports.createControlsRouter = createControlsRouter;
//# sourceMappingURL=controls.js.map