"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.evaluateAdrRequirementStatus = evaluateAdrRequirementStatus;
function slugify(value) {
    const slug = value
        .toLowerCase()
        .replace(/[^a-z0-9]+/g, '-')
        .replace(/^-+|-+$/g, '');
    return slug.length > 0 ? slug : 'architecture-change';
}
function deriveSuggestedAdrTitle(validationResults) {
    const failingIds = new Set(validationResults.filter((result) => !result.passed).map((result) => result.id));
    if ([...failingIds].some((id) => id.startsWith('AP-DEP-'))) {
        return 'document dependency governance change';
    }
    if ([...failingIds].some((id) => id.startsWith('AP-ARCH-'))) {
        return 'document module boundary change';
    }
    return 'document architecture policy exception';
}
function evaluateAdrRequirementStatus(enforcement, risk, validationResults, workspaceRoot) {
    if (enforcement.action !== 'require-adr') {
        return {
            required: false,
            satisfied: false,
            reasons: [
                `Policy outcome is ${enforcement.action.toUpperCase()}; ADR follow-up is not required.`,
                `Governance risk is ${risk.level.toUpperCase()}.`,
            ],
        };
    }
    const hasExplicitAdrCoverageSignal = validationResults.some((result) => result.id === 'AP-ADR-004' && result.passed);
    const suggestedAdrTitle = deriveSuggestedAdrTitle(validationResults);
    const suggestedCommand = `archpilot adr create "${suggestedAdrTitle}"`;
    const suggestedFilenameHint = `docs/adrs/adr-xxx-${slugify(suggestedAdrTitle)}.md`;
    if (hasExplicitAdrCoverageSignal) {
        return {
            required: true,
            satisfied: true,
            reasons: [
                'Policy outcome REQUIRE-ADR is active.',
                'AP-ADR-004 passed, which provides an explicit ADR coverage signal.',
            ],
            suggestedAdrTitle,
            suggestedCommand,
            suggestedFilenameHint,
        };
    }
    return {
        required: true,
        satisfied: false,
        reasons: [
            'Policy outcome REQUIRE-ADR is active.',
            'No explicit ADR linkage signal is currently emitted for this review context.',
            ...(workspaceRoot ? [`Workspace: ${workspaceRoot}`] : []),
        ],
        suggestedAdrTitle,
        suggestedCommand,
        suggestedFilenameHint,
    };
}
//# sourceMappingURL=adrRequirementStatus.js.map