const SEVERITY_PENALTY = {
    critical: 15,
    warn: 8,
    info: 2,
};
// SPEC-255: code-specific penalties (override severity penalty)
const CODE_PENALTY = {
    LINE_COUNT_CRITICAL: 25,
    LINE_COUNT_WARN: 10,
    AUTO_MODE_ENV_MISSING: 8,
    BYPASS_PERMISSIONS_NO_ISOLATION: 20,
};
// SPEC-255: codes with per-finding deduction and total cap
const CODE_PER_FINDING = {
    REDUNDANT_INSTRUCTION: 3,
    AMBIGUOUS_INSTRUCTION: 2,
};
const CODE_MAX_TOTAL = {
    REDUNDANT_INSTRUCTION: 15,
    AMBIGUOUS_INSTRUCTION: 10,
};
export function calculateScore(findings) {
    let score = 100;
    // Track accumulated deductions for capped codes
    const codeAccumulated = {};
    for (const f of findings) {
        const code = f.code;
        if (code !== undefined && CODE_PENALTY[code] !== undefined) {
            // Use code-specific flat penalty instead of severity penalty
            score -= CODE_PENALTY[code] ?? 0;
        }
        else if (code !== undefined && CODE_PER_FINDING[code] !== undefined) {
            // Per-finding deduction with a total cap
            const perFinding = CODE_PER_FINDING[code] ?? 0;
            const maxTotal = CODE_MAX_TOTAL[code] ?? Infinity;
            const accumulated = codeAccumulated[code] ?? 0;
            const actual = Math.min(perFinding, maxTotal - accumulated);
            if (actual > 0) {
                score -= actual;
                codeAccumulated[code] = accumulated + actual;
            }
        }
        else {
            score -= SEVERITY_PENALTY[f.severity] ?? 0;
        }
    }
    score = Math.max(0, score);
    let grade;
    if (score >= 90) {
        grade = 'A';
    }
    else if (score >= 75) {
        grade = 'B';
    }
    else if (score >= 60) {
        grade = 'C';
    }
    else if (score >= 40) {
        grade = 'D';
    }
    else {
        grade = 'F';
    }
    return { score, grade };
}
export function pickQuickWins(findings) {
    const actionable = findings.filter((f) => f.severity === 'critical' || f.severity === 'warn');
    const severityOrder = { critical: 0, warn: 1 };
    const sorted = [...actionable].sort((a, b) => {
        const sa = severityOrder[a.severity] ?? 2;
        const sb = severityOrder[b.severity] ?? 2;
        if (sa !== sb) {
            return sa - sb;
        }
        return a.suggestion.length - b.suggestion.length;
    });
    return sorted.slice(0, 3);
}
//# sourceMappingURL=scoring.js.map