"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.templatesRouter = templatesRouter;
const express_1 = require("express");
function templatesRouter(db) {
    const router = (0, express_1.Router)();
    // GET /api/v1/templates — 模板列表
    router.get("/", (_req, res) => {
        const rows = db
            .prepare("SELECT id, name, manifest FROM templates ORDER BY created_at DESC")
            .all();
        const data = rows.map((row) => {
            const manifest = JSON.parse(row.manifest);
            return {
                id: row.id,
                name: row.name,
                description: manifest.description,
                version: manifest.version,
                platforms: manifest.platforms?.available ?? [],
                assetCount: {
                    required: manifest.assets?.required?.length ?? 0,
                    optional: manifest.assets?.optional?.length ?? 0,
                },
            };
        });
        res.json({ data });
    });
    // GET /api/v1/templates/:id — 单个模板详情
    router.get("/:id", (req, res) => {
        const row = db
            .prepare("SELECT id, name, manifest FROM templates WHERE id = ?")
            .get(req.params.id);
        if (!row) {
            res.status(404).json({ error: { message: "Template not found" } });
            return;
        }
        const manifest = JSON.parse(row.manifest);
        res.json({
            data: {
                id: row.id,
                name: row.name,
                ...manifest,
            },
        });
    });
    return router;
}
//# sourceMappingURL=templates.js.map