"use strict";
/**
 * Report Summary — Sorting and counting utilities for scan results.
 *
 * Pure functions extracted from the orchestrator. No cross-stage dependencies.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.sortBySeverity = sortBySeverity;
exports.computeSeverityCounts = computeSeverityCounts;
exports.computeCategoryCounts = computeCategoryCounts;
exports.computeIssueMixFromVulnerabilities = computeIssueMixFromVulnerabilities;
const parsed_file_1 = require("../shared/parsed-file");
/**
 * Sort vulnerabilities by severity (critical first)
 */
function sortBySeverity(vulnerabilities) {
    return [...vulnerabilities].sort((a, b) => {
        const severityDiff = (0, parsed_file_1.severityRank)(b.severity) - (0, parsed_file_1.severityRank)(a.severity);
        if (severityDiff !== 0)
            return severityDiff;
        // Secondary sort by confidence
        return (0, parsed_file_1.confidenceRank)(b.confidence) - (0, parsed_file_1.confidenceRank)(a.confidence);
    });
}
/**
 * Compute severity counts from vulnerabilities
 */
function computeSeverityCounts(vulnerabilities) {
    const counts = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
    for (const vuln of vulnerabilities) {
        if (vuln.severity in counts) {
            counts[vuln.severity]++;
        }
    }
    return counts;
}
/**
 * Compute category counts from vulnerabilities
 */
function computeCategoryCounts(vulnerabilities) {
    const counts = {};
    for (const vuln of vulnerabilities) {
        const category = vuln.category;
        counts[category] = (counts[category] || 0) + 1;
    }
    return counts;
}
/**
 * Helper to compute counts from vulnerabilities (for backfilling legacy scans)
 */
function computeIssueMixFromVulnerabilities(vulnerabilities) {
    const severityCounts = computeSeverityCounts(vulnerabilities);
    const categoryCounts = computeCategoryCounts(vulnerabilities);
    const hasBlockingIssues = severityCounts.critical > 0 || severityCounts.high > 0;
    return { severityCounts, categoryCounts, hasBlockingIssues };
}
//# sourceMappingURL=summary.js.map