// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// engine/infrastructure/signal-detector.ts — Detect IaC signals in spec text (SPEC-171)
const SIGNAL_PATTERNS = [
    // Databases — specific technologies first to avoid false positives from generic patterns
    {
        type: 'database',
        technology: 'supabase',
        // supabase is its own BaaS platform, not just postgres — must be listed before postgres
        patterns: [/supabase/i],
        confidence: 'high',
    },
    {
        type: 'database',
        technology: 'postgres',
        // \bpg\b now has case-insensitive flag; supabase is excluded (handled above)
        patterns: [/postgres(ql)?/i, /\bpg\b/i],
        confidence: 'high',
    },
    {
        type: 'database',
        technology: 'mysql',
        patterns: [/mysql/i, /mariadb/i],
        confidence: 'high',
    },
    {
        type: 'database',
        technology: 'mongodb',
        patterns: [/mongo(db)?/i, /nosql/i, /document\s+store/i],
        confidence: 'high',
    },
    {
        type: 'database',
        technology: 'sqlite',
        patterns: [/sqlite/i],
        confidence: 'high',
    },
    {
        type: 'database',
        technology: 'generic',
        patterns: [/\bdatabase\b/i, /\bdb\b/i, /\bsql\b/i, /\borm\b/i, /prisma/i, /drizzle/i],
        confidence: 'medium',
    },
    // Cache — 'redis' and 'memcached' are specific; \bcache\b alone is generic
    {
        type: 'cache',
        technology: 'redis',
        patterns: [/redis/i, /memcached/i],
        confidence: 'high',
    },
    {
        type: 'cache',
        technology: 'generic',
        // \bcache\b moved here: matching "cache" without a specific technology is medium-confidence
        patterns: [/\bcach(e|ing)\b/i, /session\s+store/i, /key[\s-]value/i],
        confidence: 'medium',
    },
    // Queues / messaging
    {
        type: 'queue',
        technology: 'sqs',
        patterns: [/\bsqs\b/i, /amazon\s+queue/i],
        confidence: 'high',
    },
    {
        type: 'queue',
        technology: 'rabbitmq',
        patterns: [/rabbitmq/i, /amqp/i],
        confidence: 'high',
    },
    {
        type: 'queue',
        technology: 'kafka',
        patterns: [/kafka/i],
        confidence: 'high',
    },
    {
        type: 'queue',
        technology: 'generic',
        patterns: [/\bqueue\b/i, /message\s+broker/i, /pub[\s/-]sub/i, /event\s+bus/i],
        confidence: 'medium',
    },
    // Storage
    {
        type: 'storage',
        technology: 's3',
        patterns: [/\bs3\b/i, /object\s+storage/i, /file\s+storage/i, /blob\s+storage/i],
        confidence: 'high',
    },
    {
        type: 'storage',
        technology: 'generic',
        patterns: [/upload/i, /media\s+storage/i, /static\s+assets/i, /cdn/i],
        confidence: 'medium',
    },
    // API / deployment
    {
        type: 'api',
        technology: 'lambda',
        // /serverless/ removed here — it is more accurately classified under the 'serverless' type below
        patterns: [/\blambda\b/i, /aws\s+function/i],
        confidence: 'high',
    },
    {
        type: 'api',
        technology: 'ecs',
        patterns: [/\becs\b/i, /\bfargate\b/i, /container\s+service/i],
        confidence: 'high',
    },
    {
        type: 'api',
        technology: 'generic',
        patterns: [/rest\s+api/i, /graphql/i, /\bendpoint\b/i, /\bhttp\b/i],
        confidence: 'low',
    },
    // Kubernetes
    {
        type: 'kubernetes',
        technology: 'k8s',
        patterns: [/kubernetes/i, /\bk8s\b/i, /kubectl/i, /helm\b/i, /\bpod\b/i],
        confidence: 'high',
    },
    // Railway
    {
        type: 'railway',
        technology: 'railway',
        patterns: [/railway\.app/i, /railway\s+deploy/i, /railway\.toml/i],
        confidence: 'high',
    },
    // Serverless — /serverless/ listed only here (single source of truth for that signal)
    {
        type: 'serverless',
        technology: 'generic',
        patterns: [/serverless/i, /edge\s+function/i, /vercel/i, /netlify/i, /cloudflare\s+worker/i],
        confidence: 'medium',
    },
    // CDN
    {
        type: 'cdn',
        technology: 'cloudfront',
        patterns: [/cloudfront/i, /\bcdn\b/i, /edge\s+cach/i],
        confidence: 'medium',
    },
];
/**
 * Scan spec text for infrastructure signal patterns.
 * Returns deduplicated signals sorted by confidence (high first).
 */
export function detectInfraSignals(specText) {
    const seen = new Set();
    const signals = [];
    for (const pattern of SIGNAL_PATTERNS) {
        for (const regex of pattern.patterns) {
            const match = regex.exec(specText);
            if (!match) {
                continue;
            }
            const key = `${pattern.type}:${pattern.technology}`;
            if (seen.has(key)) {
                continue;
            }
            seen.add(key);
            signals.push({
                type: pattern.type,
                technology: pattern.technology,
                evidence: match[0],
                confidence: pattern.confidence,
            });
        }
    }
    // Sort: high > medium > low
    const order = { high: 0, medium: 1, low: 2 };
    signals.sort((a, b) => order[a.confidence] - order[b.confidence]);
    return signals;
}
//# sourceMappingURL=signal-detector.js.map