"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildNavigationCandidates = buildNavigationCandidates;
exports.resolveNavigationTargetPath = resolveNavigationTargetPath;
function extractModuleName(message) {
    const fromModulePattern = /Module '([^']+)'/u.exec(message);
    if (fromModulePattern?.[1]) {
        return fromModulePattern[1];
    }
    return undefined;
}
function extractTargetModuleName(message) {
    const fromTargetPattern = /from module '([^']+)'/u.exec(message);
    if (fromTargetPattern?.[1]) {
        return fromTargetPattern[1];
    }
    const targetContractPattern = /target module contract for '([^']+)'/u.exec(message);
    if (targetContractPattern?.[1]) {
        return targetContractPattern[1];
    }
    const importTargetPattern = /imports module '([^']+)'/u.exec(message);
    if (importTargetPattern?.[1]) {
        return importTargetPattern[1];
    }
    return undefined;
}
function extractSourceModuleName(message) {
    const sourceContractPattern = /source module contract for '([^']+)'/u.exec(message);
    if (sourceContractPattern?.[1]) {
        return sourceContractPattern[1];
    }
    return extractModuleName(message);
}
function extractArchModuleBaselinePath(message) {
    const rootMatch = /Module baseline drift detected in ([^:]+):/u.exec(message);
    const modulesRoot = rootMatch?.[1]?.trim();
    const moduleDetailsPattern = /([a-z0-9-]+)\s*\(([^)]+)\)/iu.exec(message);
    if (!moduleDetailsPattern) {
        return undefined;
    }
    const moduleName = moduleDetailsPattern[1];
    const missingDetails = moduleDetailsPattern[2].toLowerCase();
    const effectiveModulesRoot = modulesRoot && modulesRoot.length > 0 ? modulesRoot : 'src/modules';
    if (missingDetails.includes('readme.md')) {
        return `${effectiveModulesRoot}/${moduleName}/README.md`;
    }
    if (missingDetails.includes('index.ts')) {
        return `${effectiveModulesRoot}/${moduleName}/index.ts`;
    }
    return `${effectiveModulesRoot}/${moduleName}/README.md`;
}
function buildNavigationCandidates(input) {
    const { ruleId, message } = input;
    switch (ruleId) {
        case 'AP-ARCH-003':
            return ['docs/architecture/overview.md'];
        case 'AP-ARCH-004': {
            const inferredPath = extractArchModuleBaselinePath(message);
            if (inferredPath) {
                const modulesRoot = inferredPath.split('/').slice(0, -2).join('/');
                return modulesRoot.length > 0 ? [inferredPath, modulesRoot] : [inferredPath];
            }
            return ['.archpilot/architecture.json'];
        }
        case 'AP-ARCH-005':
        case 'AP-ARCH-008':
            return ['.archpilot/architecture.json'];
        case 'AP-ARCH-006': {
            const moduleName = extractModuleName(message);
            return moduleName
                ? [`.archpilot/contracts/${moduleName}.contract.json`, '.archpilot/architecture.json']
                : ['.archpilot/architecture.json'];
        }
        case 'AP-DB-001':
        case 'AP-DB-002':
            return ['db/sql/001_init.sql'];
        case 'AP-DEP-004': {
            const sourceModule = extractSourceModuleName(message);
            return sourceModule
                ? [`.archpilot/contracts/${sourceModule}.contract.json`, '.archpilot/architecture.json']
                : ['.archpilot/architecture.json'];
        }
        case 'AP-DEP-005': {
            const targetModule = extractTargetModuleName(message);
            return targetModule
                ? [`.archpilot/contracts/${targetModule}.contract.json`, '.archpilot/architecture.json']
                : ['.archpilot/architecture.json'];
        }
        case 'AP-DEP-006': {
            const sourceModule = extractSourceModuleName(message);
            return sourceModule
                ? [`.archpilot/contracts/${sourceModule}.contract.json`, '.archpilot/architecture.json']
                : ['.archpilot/architecture.json'];
        }
        case 'AP-DEP-009': {
            const moduleName = extractModuleName(message);
            return moduleName
                ? [`.archpilot/contracts/${moduleName}.contract.json`, '.archpilot/architecture.json']
                : ['.archpilot/architecture.json'];
        }
        case 'AP-DEP-010':
            return ['.archpilot/layer-rules.json'];
        case 'AP-DEP-011':
            return ['.archpilot/architecture.json'];
        case 'AP-DOC-002':
            return ['docs/architecture/overview.md'];
        case 'AP-API-001':
        case 'AP-API-002':
            return ['contracts/openapi.yaml'];
        default:
            return [];
    }
}
function resolveNavigationTargetPath(input) {
    return buildNavigationCandidates(input)[0];
}
//# sourceMappingURL=findingTargetResolution.js.map