import { GATE_CATALOG } from './gate-catalog.js';
export function selectGates(ctx) {
    return GATE_CATALOG.filter((g) => (g.specTypes.includes(ctx.specType) || g.specTypes.includes('all')) &&
        g.riskLevels.includes(ctx.risk) &&
        (g.stacks.includes(ctx.stack) || g.stacks.includes('generic')) &&
        ctx.categories.includes(g.category));
}
export function formatGatesSection(gates) {
    if (gates.length === 0) {
        return '';
    }
    const byCategory = new Map();
    for (const g of gates) {
        const list = byCategory.get(g.category) ?? [];
        list.push(g);
        byCategory.set(g.category, list);
    }
    const lines = ['\n## Quality Gates [AUTO]', ''];
    for (const [cat, catGates] of byCategory) {
        lines.push(`### ${cat.charAt(0).toUpperCase() + cat.slice(1)}`);
        for (const g of catGates) {
            lines.push(`- [ ] [AUTO] ${g.title}`);
        }
        lines.push('');
    }
    return lines.join('\n');
}
export function inferStack(language, framework) {
    const lang = (language ?? '').toLowerCase();
    const fw = (framework ?? '').toLowerCase();
    if (lang.includes('python') || fw.includes('fastapi') || fw.includes('django')) {
        return 'python';
    }
    // Check typescript/javascript BEFORE java to avoid 'javascript'.includes('java') matching
    if (lang.includes('typescript') ||
        lang.includes('javascript') ||
        fw.includes('node') ||
        fw.includes('next')) {
        return 'typescript';
    }
    if (lang === 'java' || fw.includes('spring')) {
        return 'java';
    }
    if (lang.includes('go') || fw.includes('gin') || fw.includes('fiber')) {
        return 'go';
    }
    return 'generic';
}
export function injectQualityGates(params) {
    const stack = inferStack(params.language, params.framework);
    const categories = params.categories ?? [
        'security',
        'testing',
        'architecture',
        'performance',
    ];
    const gates = selectGates({
        specType: params.specType,
        risk: params.risk,
        stack,
        categories,
    });
    return {
        gates,
        markdownSection: formatGatesSection(gates),
        count: gates.length,
        categoryCounts: {
            security: gates.filter((g) => g.category === 'security').length,
            testing: gates.filter((g) => g.category === 'testing').length,
            architecture: gates.filter((g) => g.category === 'architecture').length,
            performance: gates.filter((g) => g.category === 'performance').length,
        },
    };
}
//# sourceMappingURL=gate-injector.js.map