"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Skill Admin Routes
 *
 * API endpoints for skill management (CRUD operations).
 */
const express_1 = __importDefault(require("express"));
const skillAdminController_1 = __importDefault(require("../controllers/skillAdminController"));
const config_1 = require("../config");
const auth_1 = require("../middleware/auth");
const router = express_1.default.Router();
const skillAdminController = new skillAdminController_1.default();
const CUSTOM_SKILL_DISABLED_PAYLOAD = {
    error: 'disabled_in_enterprise_mode',
    details: 'Custom skill write endpoints are disabled in enterprise mode.',
};
function disableCustomSkillWritesInEnterpriseMode(_req, res, next) {
    if ((0, config_1.resolveFeatureConfig)().enterprise) {
        res.status(404).json(CUSTOM_SKILL_DISABLED_PAYLOAD);
        return;
    }
    next();
}
// Admin endpoints must always be authenticated.
router.use(auth_1.authenticate);
// =============================================================================
// Skill CRUD
// =============================================================================
/**
 * GET /api/admin/skills
 *
 * List all skills with admin metadata
 */
router.get('/skills', skillAdminController.listSkills);
/**
 * GET /api/admin/skills/:skillId
 *
 * Get skill details including raw YAML
 */
router.get('/skills/:skillId', skillAdminController.getSkill);
/**
 * POST /api/admin/skills
 *
 * Create a new custom skill
 * Body: { yaml: string } or { definition: SkillDefinition }
 */
router.post('/skills', disableCustomSkillWritesInEnterpriseMode, skillAdminController.createSkill);
/**
 * PUT /api/admin/skills/:skillId
 *
 * Update an existing custom skill
 * Body: { yaml: string } or { definition: SkillDefinition }
 */
router.put('/skills/:skillId', disableCustomSkillWritesInEnterpriseMode, skillAdminController.updateSkill);
/**
 * DELETE /api/admin/skills/:skillId
 *
 * Delete a custom skill
 */
router.delete('/skills/:skillId', disableCustomSkillWritesInEnterpriseMode, skillAdminController.deleteSkill);
// =============================================================================
// Validation
// =============================================================================
/**
 * POST /api/admin/skills/validate
 *
 * Validate skill YAML without saving
 * Body: { yaml: string }
 */
router.post('/skills/validate', skillAdminController.validateSkill);
/**
 * POST /api/admin/skills/reload
 *
 * Reload all skills from disk
 */
router.post('/skills/reload', skillAdminController.reloadSkills);
// =============================================================================
// Vendor Management
// =============================================================================
/**
 * GET /api/admin/vendors
 *
 * List all vendors with override counts
 */
router.get('/vendors', skillAdminController.listVendors);
/**
 * GET /api/admin/vendors/:vendor/overrides
 *
 * Get all overrides for a specific vendor
 */
router.get('/vendors/:vendor/overrides', skillAdminController.getVendorOverrides);
exports.default = router;
//# sourceMappingURL=skillAdminRoutes.js.map