const CONTRADICTION_RULES = [
    {
        questionAKeyword: 'deadline',
        questionBKeyword: 'priority',
        answerAKeyword: 'no hard deadline',
        answerBKeyword: 'blocking',
        message: 'No deadline was mentioned but the feature is marked as blocking other work.',
    },
    {
        questionAKeyword: 'authentication',
        questionBKeyword: 'target users',
        answerAKeyword: 'no auth',
        answerBKeyword: 'admin',
        message: 'No authentication was specified but admin-only access was mentioned.',
    },
    {
        questionAKeyword: 'performance',
        questionBKeyword: 'data volume',
        answerAKeyword: 'no strict',
        answerBKeyword: 'millions',
        message: 'No performance SLA was set but high data volume was mentioned.',
    },
    {
        questionAKeyword: 'external service',
        questionBKeyword: 'depend',
        answerAKeyword: 'no external',
        answerBKeyword: 'api',
        message: 'Answer says no external dependencies but another answer mentions an API dependency.',
    },
];
/** Detect semantic contradictions between answers to different questions. */
export function detectContradictions(questions, answers) {
    const contradictions = [];
    // Build lookup: question text → answer
    const qAnswers = questions
        .filter((q) => answers[q.id] !== undefined && answers[q.id] !== '')
        .map((q) => ({
        question: q.question.toLowerCase(),
        answer: (answers[q.id] ?? '').toLowerCase(),
    }));
    for (const rule of CONTRADICTION_RULES) {
        const entryA = qAnswers.find((qa) => qa.question.includes(rule.questionAKeyword) && qa.answer.includes(rule.answerAKeyword));
        const entryB = qAnswers.find((qa) => qa.question.includes(rule.questionBKeyword) && qa.answer.includes(rule.answerBKeyword));
        if (entryA && entryB) {
            contradictions.push(rule.message);
        }
    }
    return contradictions;
}
/** Evaluate whether enough critical questions are answered to be spec-ready. */
export function evaluateSpecReadiness(questions, answers) {
    const criticalQuestions = questions.filter((q) => q.importance === 'critical');
    if (criticalQuestions.length === 0) {
        return true;
    }
    const answeredCritical = criticalQuestions.filter((q) => answers[q.id] !== undefined && (answers[q.id] ?? '').trim() !== '');
    return answeredCritical.length === criticalQuestions.length;
}
/** Generate follow-up questions based on provided answers. */
export function generateFollowUpQuestions(questions, answers) {
    const followUps = [];
    let idxCounter = questions.length;
    for (const q of questions) {
        if (!q.followUpIf) {
            continue;
        }
        const answer = (answers[q.id] ?? '').toLowerCase();
        for (const [triggerKeyword, followUpQuestion] of Object.entries(q.followUpIf)) {
            if (answer.includes(triggerKeyword.toLowerCase())) {
                const alreadyPresent = questions.some((existing) => existing.question === followUpQuestion);
                if (!alreadyPresent) {
                    idxCounter++;
                    followUps.push({
                        id: `fq-${idxCounter}`,
                        question: followUpQuestion,
                        category: q.category,
                        importance: 'helpful',
                    });
                }
            }
        }
    }
    return followUps;
}
//# sourceMappingURL=contradictions.js.map