"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compareDriftSnapshots = compareDriftSnapshots;
function compareViolation(left, right) {
    const ruleCompare = left.ruleId.localeCompare(right.ruleId);
    if (ruleCompare !== 0) {
        return ruleCompare;
    }
    const fileCompare = (left.file ?? '').localeCompare(right.file ?? '');
    if (fileCompare !== 0) {
        return fileCompare;
    }
    const severityCompare = left.severity.localeCompare(right.severity);
    if (severityCompare !== 0) {
        return severityCompare;
    }
    return (left.message ?? '').localeCompare(right.message ?? '');
}
function toViolationKey(value) {
    return `${value.ruleId}::${value.severity}::${value.file ?? ''}::${value.message ?? ''}`;
}
function compareDriftSnapshots(previousSnapshot, currentSnapshot) {
    if (!previousSnapshot) {
        return {
            hasPreviousSnapshot: false,
            newViolations: [],
            resolvedViolations: [],
        };
    }
    const previousViolationMap = new Map(previousSnapshot.violations.map((violation) => [toViolationKey(violation), violation]));
    const currentViolationMap = new Map(currentSnapshot.violations.map((violation) => [toViolationKey(violation), violation]));
    const newViolations = currentSnapshot.violations
        .filter((violation) => !previousViolationMap.has(toViolationKey(violation)))
        .sort(compareViolation);
    const resolvedViolations = previousSnapshot.violations
        .filter((violation) => !currentViolationMap.has(toViolationKey(violation)))
        .sort(compareViolation);
    return {
        hasPreviousSnapshot: true,
        previousScore: previousSnapshot.score,
        scoreDelta: currentSnapshot.score - previousSnapshot.score,
        errorDelta: currentSnapshot.errors - previousSnapshot.errors,
        warningDelta: currentSnapshot.warnings - previousSnapshot.warnings,
        infoDelta: currentSnapshot.info - previousSnapshot.info,
        newViolations,
        resolvedViolations,
    };
}
//# sourceMappingURL=driftComparator.js.map