// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// engine/decision-store.ts — Search and conflict detection for decisions (SPEC-040)
// Pure functions — no I/O. All persistence is in storage/decision-store.ts.
// ---------------------------------------------------------------------------
// Keyword maps
// ---------------------------------------------------------------------------
const STACK_KEYWORDS = [
    'react',
    'vue',
    'angular',
    'svelte',
    'next',
    'nuxt',
    'remix',
    'node',
    'deno',
    'bun',
    'python',
    'java',
    'kotlin',
    'swift',
    'flutter',
    'expo',
    'typescript',
    'javascript',
    'rust',
    'go',
    'postgres',
    'mysql',
    'mongodb',
    'redis',
    'sqlite',
];
const ARCHITECTURE_KEYWORDS = [
    'monolith',
    'microservice',
    'monorepo',
    'serverless',
    'event-driven',
    'cqrs',
    'ddd',
    'hexagonal',
    'clean architecture',
    'layered',
    'rest',
    'graphql',
    'grpc',
    'message queue',
    'kafka',
    'rabbitmq',
];
const UX_KEYWORDS = [
    'design system',
    'ui',
    'ux',
    'component library',
    'accessibility',
    'dark mode',
    'mobile first',
    'responsive',
    'navigation',
    'routing',
    'animation',
    'form',
    'layout',
    'typography',
];
const BUSINESS_KEYWORDS = [
    'pricing',
    'billing',
    'subscription',
    'freemium',
    'enterprise',
    'compliance',
    'gdpr',
    'hipaa',
    'sla',
    'support plan',
    'revenue',
    'launch date',
    'mvp',
    'rollout',
    'market',
];
// ---------------------------------------------------------------------------
// findConflictingDecisions
// ---------------------------------------------------------------------------
/**
 * Find active decisions that may conflict with a proposed change.
 * Uses keyword overlap between the proposal and decision.what + decision.why.
 */
export function findConflictingDecisions(proposal, decisions) {
    const proposalWords = tokenize(proposal);
    return decisions.filter((d) => {
        if (d.status !== 'active') {
            return false;
        }
        const decisionWords = tokenize(`${d.what} ${d.why}`);
        const overlap = proposalWords.filter((w) => decisionWords.includes(w));
        return overlap.length >= 2;
    });
}
// ---------------------------------------------------------------------------
// searchDecisions
// ---------------------------------------------------------------------------
/**
 * Basic full-text search in decision.what and decision.why.
 * Returns decisions containing any token from the query.
 */
export function searchDecisions(query, decisions) {
    const queryTokens = tokenize(query);
    if (queryTokens.length === 0) {
        return [];
    }
    return decisions.filter((d) => {
        const text = `${d.what} ${d.why} ${d.alternatives.join(' ')}`.toLowerCase();
        return queryTokens.some((token) => text.includes(token));
    });
}
// ---------------------------------------------------------------------------
// categorizeDecision
// ---------------------------------------------------------------------------
/**
 * Infer the most likely DecisionCategory from the content of a decision.
 * Falls back to 'process' when no keywords match.
 */
export function categorizeDecision(what, why) {
    const text = `${what} ${why}`.toLowerCase();
    const stackScore = STACK_KEYWORDS.filter((kw) => text.includes(kw)).length;
    const archScore = ARCHITECTURE_KEYWORDS.filter((kw) => text.includes(kw)).length;
    const uxScore = UX_KEYWORDS.filter((kw) => text.includes(kw)).length;
    const businessScore = BUSINESS_KEYWORDS.filter((kw) => text.includes(kw)).length;
    const max = Math.max(stackScore, archScore, uxScore, businessScore);
    if (max === 0) {
        return 'process';
    }
    if (archScore === max) {
        return 'architecture';
    }
    if (stackScore === max) {
        return 'stack';
    }
    if (uxScore === max) {
        return 'ux';
    }
    return 'business';
}
// ---------------------------------------------------------------------------
// Internal helpers
// ---------------------------------------------------------------------------
function tokenize(text) {
    return text
        .toLowerCase()
        .split(/\W+/)
        .filter((w) => w.length >= 3);
}
//# sourceMappingURL=decision-store.js.map