// engine/auditor-scoring.ts — Weighted SOLID quality scoring per category
// SPEC-010: calculates QualityScore with category breakdown (SOLID 25%, Clean Code 20%...)
// Weights per category (must sum to 1.0)
const CATEGORY_WEIGHTS = {
    solid: 0.25,
    'clean-code': 0.2,
    architecture: 0.2,
    security: 0.15,
    performance: 0.1,
    dry: 0.05,
    'error-handling': 0.05,
};
const SCORING_CATEGORIES = [
    'solid',
    'clean-code',
    'architecture',
    'security',
    'performance',
    'dry',
    'error-handling',
];
const SEVERITY_PENALTY = {
    critical: 25,
    error: 12,
    warning: 5,
    info: 1,
};
/**
 * Calculate weighted quality score from audit findings.
 * Returns a QualityScore with per-category breakdown and overall 0-100 score.
 */
export function calcQualityScore(findings, customResults = []) {
    const categories = SCORING_CATEGORIES.map((category) => scoreSingleCategory(category, findings));
    // Weighted average of all category scores
    const overall = Math.round(categories.reduce((sum, cat) => sum + cat.score * cat.weight, 0));
    return {
        overall: Math.max(0, Math.min(100, overall)),
        categories,
        customRules: customResults,
        generatedAt: new Date().toISOString(),
    };
}
function scoreSingleCategory(category, findings) {
    // Map QualityScoringCategory to AuditCategory (they overlap)
    const catFindings = findings.filter((f) => f.category === category);
    const weight = CATEGORY_WEIGHTS[category];
    if (catFindings.length === 0) {
        return {
            category,
            score: 100,
            weight,
            issueCount: 0,
            worstSeverity: 'none',
            suggestions: [],
        };
    }
    // Calculate penalty
    let penalty = 0;
    let worstSeverity = 'info';
    const severityOrder = { critical: 4, error: 3, warning: 2, info: 1, none: 0 };
    for (const f of catFindings) {
        /* v8 ignore start */
        penalty += SEVERITY_PENALTY[f.severity] ?? 2;
        const fOrder = severityOrder[f.severity] ?? 0;
        const worstOrder = severityOrder[worstSeverity] ?? 0;
        /* v8 ignore stop */
        if (fOrder > worstOrder) {
            worstSeverity = f.severity;
        }
    }
    const score = Math.max(0, Math.min(100, 100 - penalty));
    // Top 3 unique suggestions
    const suggestions = [...new Set(catFindings.map((f) => f.suggestion))].slice(0, 3);
    return { category, score, weight, issueCount: catFindings.length, worstSeverity, suggestions };
}
//# sourceMappingURL=auditor-scoring.js.map