// analyzer-linting/registry.ts — Linter registry loading and conflict detection
import { readFile } from 'node:fs/promises';
let registryCache = null;
/** Resets the in-memory cache — used in tests to force reload */
export function resetLinterRegistryCache() {
    registryCache = null;
}
export async function loadLinterRegistry() {
    if (registryCache) {
        return registryCache;
    }
    try {
        const configPath = new URL('../../config/linter-registry.json', import.meta.url);
        const content = await readFile(configPath, 'utf-8');
        registryCache = JSON.parse(content);
        return registryCache;
    }
    catch {
        return { conflicts: [] };
    }
}
export function detectLinterConflictsFromRegistry(linters, registry) {
    const conflicts = [];
    const tools = new Set(linters.map((l) => l.tool));
    const registryConflicts = registry.conflicts;
    for (const conflict of registryConflicts) {
        const [lintA, lintB] = conflict.linters;
        if (lintA && lintB && tools.has(lintA) && tools.has(lintB)) {
            conflicts.push({
                linterA: lintA,
                linterB: lintB,
                conflict: conflict.description,
                resolution: conflict.resolution,
            });
        }
    }
    return conflicts;
}
export async function getLinterRecommendations(language) {
    const registry = await loadLinterRegistry();
    const langEntry = registry[language.toLowerCase()];
    if (!langEntry) {
        return null;
    }
    return {
        language,
        recommended: langEntry.recommended,
        transversal: langEntry.transversal,
        reasoning: buildReasoningText(language, langEntry),
    };
}
function buildReasoningText(language, entry) {
    const recs = entry.recommended.join(', ');
    return `For ${language} projects: ${recs} provide comprehensive linting and formatting coverage.`;
}
export async function getDetailedConflicts(detectedTools) {
    const registry = await loadLinterRegistry();
    const tools = new Set(detectedTools);
    const result = [];
    for (const conflict of registry.conflicts) {
        const [a, b] = conflict.linters;
        if (a && b && tools.has(a) && tools.has(b)) {
            result.push({
                linters: [a, b],
                conflictType: conflict.conflictType,
                description: conflict.description,
                resolution: conflict.resolution,
            });
        }
    }
    return result;
}
//# sourceMappingURL=registry.js.map