"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatDriftAreaLabel = formatDriftAreaLabel;
exports.getDriftAreasFromResults = getDriftAreasFromResults;
exports.formatArchitectureDriftSummaryMessage = formatArchitectureDriftSummaryMessage;
exports.buildArchitectureDriftSummary = buildArchitectureDriftSummary;
const driftAreaOrder = [
    'module structure',
    'required architecture artifacts',
    'API contract artifacts',
    'dependency boundaries',
    'database artifacts',
    'documentation artifacts',
    'security controls',
];
function formatDriftAreaLabel(area) {
    return area;
}
function getDriftAreaForRule(ruleId) {
    if (ruleId === 'AP-ARCH-004') {
        return 'module structure';
    }
    if (ruleId === 'AP-ARCH-003') {
        return 'required architecture artifacts';
    }
    if (ruleId === 'AP-ARCH-005') {
        return 'module structure';
    }
    if (ruleId === 'AP-ARCH-006' || ruleId === 'AP-ARCH-007' || ruleId === 'AP-ARCH-008') {
        return 'required architecture artifacts';
    }
    if (ruleId.startsWith('AP-API-')) {
        return 'API contract artifacts';
    }
    if (ruleId === 'AP-DEP-001' ||
        ruleId === 'AP-DEP-002' ||
        ruleId === 'AP-DEP-003' ||
        ruleId === 'AP-DEP-004' ||
        ruleId === 'AP-DEP-005' ||
        ruleId === 'AP-DEP-006' ||
        ruleId === 'AP-DEP-008' ||
        ruleId === 'AP-DEP-010') {
        return 'dependency boundaries';
    }
    if (ruleId.startsWith('AP-DB-')) {
        return 'database artifacts';
    }
    if (ruleId.startsWith('AP-DOC-')) {
        return 'documentation artifacts';
    }
    return undefined;
}
function getDriftAreasFromResults(results) {
    const areaSet = new Set();
    for (const result of results) {
        if (!result.passed) {
            const area = getDriftAreaForRule(result.id);
            if (area && driftAreaOrder.includes(area)) {
                areaSet.add(area);
            }
        }
    }
    return driftAreaOrder.filter((area) => areaSet.has(area));
}
function formatArchitectureDriftSummaryMessage(areas) {
    if (areas.length === 0) {
        return 'No architecture drift detected based on current structural validation checks.';
    }
    const labels = areas.map((area) => formatDriftAreaLabel(area));
    if (labels.length === 1) {
        return `Architecture drift detected in ${labels[0]}.`;
    }
    if (labels.length === 2) {
        return `Architecture drift detected in ${labels[0]} and ${labels[1]}.`;
    }
    return `Architecture drift detected in ${labels.slice(0, -1).join(', ')}, and ${labels.at(-1)}.`;
}
function buildArchitectureDriftSummary(results, _suppressedResults = [], options = {}) {
    if (options.baselineAvailable !== true) {
        return {
            detected: false,
            areas: [],
            message: 'No comparison baseline available; architecture drift was not evaluated.',
            baselineAvailable: false,
        };
    }
    const activeFailedResults = results.filter((result) => !result.passed && result.severity !== 'info');
    const areas = getDriftAreasFromResults(activeFailedResults);
    return {
        detected: areas.length > 0,
        areas,
        message: formatArchitectureDriftSummaryMessage(areas),
        baselineAvailable: true,
    };
}
//# sourceMappingURL=architectureDriftDetection.js.map