// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// engine/resilience-detector/concurrency-detector.ts — Concurrency model & resilience detection (SPEC-034)
/**
 * Detects concurrency model based on language and runtime.
 */
export function detectConcurrencyModel(language, deps) {
    const langLower = language.toLowerCase();
    const depsLower = deps.map((d) => d.toLowerCase());
    if (langLower === 'go') {
        return 'goroutines';
    }
    if (langLower === 'rust') {
        return 'rust-ownership';
    }
    if (langLower === 'erlang' || langLower === 'elixir') {
        return 'actor-model';
    }
    if (langLower === 'java' || langLower === 'kotlin') {
        if (depsLower.some((d) => d.includes('akka'))) {
            return 'actor-model';
        }
        if (depsLower.some((d) => d.includes('rxjava') ||
            d.includes('reactor-core') ||
            d.includes('spring-webflux') ||
            d.includes('rxkotlin'))) {
            return 'reactive-streams';
        }
        return 'threads-locks';
    }
    if (langLower === 'typescript' || langLower === 'javascript' || langLower === 'nodejs') {
        if (depsLower.some((d) => d.includes('rxjs'))) {
            return 'reactive-streams';
        }
        return 'async-await';
    }
    if (langLower === 'python') {
        return 'async-await';
    }
    if (langLower === 'csharp' || langLower === 'c#' || langLower === 'dotnet') {
        if (depsLower.some((d) => d.includes('system.reactive') || d.includes('rx.net'))) {
            return 'reactive-streams';
        }
        return 'async-await';
    }
    if (langLower === 'dart') {
        return 'async-await';
    }
    if (langLower === 'ruby') {
        return 'green-threads';
    }
    /* v8 ignore next 1 */
    return 'unknown';
}
const RESILIENCE_CATALOG = [
    {
        language: 'java',
        name: 'resilience4j',
        detectionPatterns: ['resilience4j', 'io.github.resilience4j'],
        patterns: ['circuit-breaker', 'retry', 'rate-limiter', 'bulkhead'],
    },
    {
        language: 'java',
        name: 'hystrix',
        detectionPatterns: ['hystrix', 'com.netflix.hystrix'],
        status: 'legacy',
        migrationNote: 'Hystrix is in maintenance mode since 2018. Migrate to Resilience4j.',
        patterns: ['circuit-breaker', 'fallback'],
    },
    {
        language: 'java',
        name: 'spring-retry',
        detectionPatterns: ['spring-retry', 'org.springframework.retry'],
        patterns: ['retry'],
    },
    {
        language: 'dotnet',
        name: 'polly',
        detectionPatterns: ['polly', 'microsoft.extensions.http.polly'],
        patterns: ['circuit-breaker', 'retry', 'timeout', 'bulkhead'],
    },
    {
        language: 'python',
        name: 'stamina',
        detectionPatterns: ['stamina'],
        patterns: ['retry'],
    },
    {
        language: 'python',
        name: 'tenacity',
        detectionPatterns: ['tenacity'],
        patterns: ['retry'],
    },
    {
        language: 'python',
        name: 'pybreaker',
        detectionPatterns: ['pybreaker'],
        patterns: ['circuit-breaker'],
    },
    {
        language: 'go',
        name: 'failsafe-go',
        detectionPatterns: ['failsafe-go', 'failsafe-go/failsafe-go'],
        patterns: ['circuit-breaker', 'retry', 'timeout', 'bulkhead'],
    },
    {
        language: 'go',
        name: 'gobreaker',
        detectionPatterns: ['gobreaker', 'sony/gobreaker'],
        patterns: ['circuit-breaker'],
    },
    {
        language: 'nodejs',
        name: 'opossum',
        detectionPatterns: ['opossum'],
        patterns: ['circuit-breaker'],
    },
    {
        language: 'nodejs',
        name: 'p-retry',
        detectionPatterns: ['p-retry'],
        patterns: ['retry'],
    },
    {
        language: 'nodejs',
        name: 'cockatiel',
        detectionPatterns: ['cockatiel'],
        patterns: ['circuit-breaker', 'retry', 'timeout', 'bulkhead'],
    },
    {
        language: 'rust',
        name: 'tokio-retry',
        detectionPatterns: ['tokio-retry'],
        patterns: ['retry'],
    },
];
const LANG_ALIASES = {
    typescript: 'nodejs',
    javascript: 'nodejs',
    kotlin: 'java',
    'c#': 'dotnet',
    csharp: 'dotnet',
};
/**
 * Detects installed resilience libraries for the given language and dependency set.
 */
export function detectResilienceLibraries(deps, language) {
    const depsLower = deps.map((d) => d.toLowerCase());
    const normalizedLang = LANG_ALIASES[language] ?? language;
    const found = [];
    for (const entry of RESILIENCE_CATALOG) {
        if (entry.language !== normalizedLang) {
            continue;
        }
        const detected = entry.detectionPatterns.some((p) => depsLower.some((d) => d.includes(p.toLowerCase())));
        if (detected) {
            found.push({
                name: entry.name,
                patterns: entry.patterns,
                isLegacy: entry.status === 'legacy',
                migrationNote: entry.migrationNote,
            });
        }
    }
    return found;
}
//# sourceMappingURL=concurrency-detector.js.map