// Planu — Severity Ranker (SPEC-483)
// Sorts findings by severity (critical first) then by line number (ascending).
/** Ordinal weight for each severity level — lower = higher priority. */
const SEVERITY_ORDER = {
    critical: 0,
    high: 1,
    medium: 2,
    low: 3,
    nit: 4,
};
/**
 * Sorts findings by severity (highest first) then by file and line (ascending).
 * Returns a new array — does not mutate the input.
 */
export function rankFindings(findings) {
    return [...findings].sort((a, b) => {
        const severityDiff = SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity];
        if (severityDiff !== 0) {
            return severityDiff;
        }
        const fileDiff = a.file.localeCompare(b.file);
        if (fileDiff !== 0) {
            return fileDiff;
        }
        return a.line - b.line;
    });
}
/**
 * Builds the counts record from a list of (already ranked) findings.
 */
export function buildCounts(findings) {
    const counts = {
        critical: 0,
        high: 0,
        medium: 0,
        low: 0,
        nit: 0,
    };
    for (const f of findings) {
        counts[f.severity]++;
    }
    return counts;
}
/**
 * Assembles the final MARReport from ranked findings and scanned file paths.
 */
export function buildReport(rankedFindings, scannedFiles) {
    return {
        totalFindings: rankedFindings.length,
        counts: buildCounts(rankedFindings),
        findings: rankedFindings,
        reviewedAt: new Date().toISOString(),
        scannedFiles,
    };
}
//# sourceMappingURL=severity-ranker.js.map