"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildPresetsRouter = buildPresetsRouter;
const express_1 = require("express");
const nanoid_1 = require("nanoid");
const config_1 = require("../config");
const promptBuilder_1 = require("../services/promptBuilder");
const traceLogger_1 = require("../services/traceLogger");
const http_1 = require("../utils/http");
function buildPresetsRouter() {
    const router = (0, express_1.Router)();
    router.get("/api/presets", (_req, res) => {
        const stored = (0, traceLogger_1.listPresets)();
        const builtin = (0, promptBuilder_1.listBuiltinPromptPresets)();
        const combined = [...builtin, ...stored];
        (0, http_1.ok)(res, {
            ok: true,
            default_prompt_version: config_1.DEFAULT_PROMPT_VERSION,
            presets: combined
        });
    });
    router.post("/api/presets/save", (req, res, next) => {
        try {
            const body = (req.body ?? {});
            const now = new Date().toISOString();
            const preset = {
                id: body.id ?? `preset-${(0, nanoid_1.nanoid)(8)}`,
                name: body.name ?? "Пользовательский пресет",
                createdAt: body.createdAt ?? now,
                updatedAt: now,
                prompt_version: body.prompt_version ?? config_1.DEFAULT_PROMPT_VERSION,
                systemPrompt: body.systemPrompt ?? "",
                developerPrompt: body.developerPrompt ?? "",
                domainPrompt: body.domainPrompt ?? "",
                schemaNotes: body.schemaNotes ?? "",
                fewShotExamples: body.fewShotExamples ?? ""
            };
            (0, traceLogger_1.savePreset)(preset);
            (0, http_1.created)(res, {
                ok: true,
                preset
            });
        }
        catch (error) {
            next(error);
        }
    });
    return router;
}
