"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.classifyValidationSourceScope = classifyValidationSourceScope;
exports.isProductionBackendGovernanceScope = isProductionBackendGovernanceScope;
function normalizePath(value) {
    return value.replace(/\\/g, '/').toLowerCase();
}
function hasPathSegment(pathValue, pattern) {
    return pathValue.split('/').some((segment) => pattern.test(segment));
}
function hasTopLevelPathSegment(pathValue, pattern) {
    const [firstSegment] = pathValue.split('/');
    return !!firstSegment && pattern.test(firstSegment);
}
function classifyValidationSourceScope(relativePath) {
    const normalized = normalizePath(relativePath);
    const fileName = normalized.split('/').at(-1) ?? normalized;
    const extension = fileName.includes('.') ? fileName.slice(fileName.lastIndexOf('.')) : '';
    const isTestFile = /\.(?:spec|test|e2e-spec|integration-test)\.(?:ts|tsx|js|jsx|mjs|cjs|java|cs|py|php|go)$/u.test(fileName);
    const isE2e = isTestFile && /(?:^|[./_-])e2e(?:[./_-]|$)/u.test(fileName) || hasPathSegment(normalized, /^e2e$/u);
    const isFixture = hasPathSegment(normalized, /^(?:fixtures?|__fixtures__)$/u);
    const isTestPlugin = hasPathSegment(normalized, /^(?:test-plugins?|testing-plugins?)$/u);
    const isExamplePlugin = hasPathSegment(normalized, /^example-plugins?$/u) ||
        hasTopLevelPathSegment(normalized, /^examples?$/u);
    const isGenerated = hasPathSegment(normalized, /^(?:generated|__generated__|gen|templates?)$/u) ||
        /\.(?:generated|gen|g)\.(?:ts|tsx|js|jsx|java|cs|py|php|go)$/u.test(fileName) ||
        /\.d\.ts$/u.test(fileName);
    const isMigration = hasPathSegment(normalized, /^(?:migrations?|schema-migrations?|data-migrations|migration-utils?)$/u);
    const isCliTooling = hasPathSegment(normalized, /^(?:cli|bin|scripts?|tools?|scaffold|scaffolding|generators?)$/u) ||
        /(?:^|[./_-])(?:cli|script|tool|generator|scaffold)(?:[./_-]|$)/u.test(fileName);
    const isFrontend = extension === '.tsx' ||
        extension === '.jsx' ||
        hasPathSegment(normalized, /^(?:frontend|client|browser|ui|admin-ui|dashboard|web-app)$/u) ||
        /\b(?:react|angular|vue|svelte)\b/u.test(normalized);
    const isInfrastructure = hasPathSegment(normalized, /^(?:infrastructure|infra|framework|adapters?|persistence|providers?)$/u) ||
        /(?:transactional-connection|transaction-wrapper|transaction-subscriber|transaction-manager|query-runner|query-builder|event-bus|telemetry|interceptor)\.(?:ts|js|java|cs|py|php|go)$/u.test(fileName);
    let category = 'production-backend';
    if (isGenerated) {
        category = 'generated';
    }
    else if (isE2e) {
        category = 'e2e';
    }
    else if (isTestFile || hasPathSegment(normalized, /^(?:test|tests|__tests__|spec|specs|__mocks__|cypress|cypress-tests)$/u)) {
        category = 'test';
    }
    else if (isTestPlugin) {
        category = 'test-plugin';
    }
    else if (isExamplePlugin) {
        category = 'example-plugin';
    }
    else if (isFixture) {
        category = 'fixture';
    }
    else if (isMigration) {
        category = 'migration';
    }
    else if (isCliTooling) {
        category = 'cli-tooling';
    }
    else if (isFrontend) {
        category = 'production-frontend';
    }
    else if (isInfrastructure) {
        category = 'infrastructure';
    }
    const isTestLike = category === 'test' || category === 'e2e' || category === 'fixture' || category === 'test-plugin' || category === 'example-plugin';
    return {
        category,
        isProduction: category === 'production-backend' || category === 'production-frontend' || category === 'infrastructure',
        isFrontend: category === 'production-frontend',
        isTestLike,
        isGenerated: category === 'generated',
        isMigration: category === 'migration',
        isCliTooling: category === 'cli-tooling',
        isInfrastructure: category === 'infrastructure',
    };
}
function isProductionBackendGovernanceScope(scope) {
    return scope.category === 'production-backend';
}
//# sourceMappingURL=sourceScopeClassification.js.map