// tools/register-template-tools.ts — Registers spec template tools on the MCP server.
import { z } from 'zod';
import { safeTracked, safeLicensed } from './safe-handler.js';
import { handleListTemplates, handleApplyTemplate } from './spec-templates.js';
const TEMPLATE_CATEGORIES = [
    'auth',
    'crud',
    'api',
    'ui',
    'infra',
    'testing',
    'integration',
    'data',
    'security',
    'performance',
    'industry',
];
const COMPLEXITY_SCORES = ['S', 'M', 'L', 'XL'];
/**
 * Registers spec template tools on the MCP server.
 * - list_templates: free, tracked
 * - apply_template: Pro (license-gated)
 */
export function registerTemplateTools(server) {
    // list_templates — browse and discover templates
    server.registerTool('list_templates', {
        description: 'Browse the built-in and custom spec template catalog. Returns available templates with descriptions, ' +
            'categories, tags, complexity scores, and required variables. ' +
            'Custom templates in data/global/spec-templates/custom/ are included automatically. ' +
            'Use apply_template to create a spec from a template.',
        inputSchema: {
            category: z
                .enum(TEMPLATE_CATEGORIES)
                .optional()
                .describe('Filter templates by category. Type: auth | crud | api | ui | infra | testing | integration | data | security | performance | industry'),
            search: z
                .string()
                .optional()
                .describe('Full-text search across template names, descriptions, and tags (case-insensitive)'),
            complexityScore: z
                .enum(COMPLEXITY_SCORES)
                .optional()
                .describe('Filter by complexity score. Type: S (<16h) | M (16-40h) | L (40-80h) | XL (>80h)'),
        },
        annotations: { title: 'List Spec Templates', readOnlyHint: true },
    }, safeTracked('list_templates', async (args) => handleListTemplates(args)));
    // apply_template — create spec files from a template
    server.registerTool('apply_template', {
        description: 'Create HU.md, FICHA-TECNICA.md, and PROGRESS.md from a spec template. ' +
            'Templates are language-agnostic and cover common feature patterns (auth, CRUD, API, etc.) and industry verticals (fintech, healthtech, e-commerce, SaaS). ' +
            'Use list_templates first to discover available templates and their required variables. ' +
            'Supports partial criteria selection via includeCriteria parameter.',
        inputSchema: {
            templateId: z
                .string()
                .describe('ID of the template to apply (e.g. "auth-jwt", "fintech-kyc"). Use list_templates to get valid IDs.'),
            projectPath: z
                .string()
                .describe('Absolute path to the project root where specs will be created'),
            variables: z
                .array(z.object({
                key: z
                    .string()
                    .describe('Variable key as defined in the template (e.g. "EntityName")'),
                value: z.string().describe('Value to substitute for this variable (e.g. "Product")'),
            }))
                .describe('Template variable substitutions. Use list_templates to see required variables for each template.'),
            feature: z
                .string()
                .optional()
                .describe('Feature group name (e.g. "Authentication", "Products"). Specs are organized under planu/specs/{feature}/. Defaults to _general.'),
            outputDir: z
                .string()
                .optional()
                .describe('Custom absolute path for the output directory. Overrides the default planu/specs/{feature}/{template-id}/ layout.'),
            includeCriteria: z
                .array(z.string())
                .optional()
                .describe('List of criteria IDs to include (e.g. ["AC-1", "AC-3"]). Omit to include all criteria. Required criteria are always included even if omitted from this list.'),
        },
        annotations: { title: 'Apply Spec Template', destructiveHint: false },
    }, safeLicensed('apply_template', async (args) => handleApplyTemplate(args)));
}
//# sourceMappingURL=register-template-tools.js.map