import { loadDeprecationPatterns } from './pattern-loader.js';
import { scanForDeprecations } from './source-scanner.js';
// ---------------------------------------------------------------------------
// Tech debt estimation
// ---------------------------------------------------------------------------
/** Estimate tech-debt hours from deprecation findings. */
export function estimateTechDebt(findings) {
    let hours = 0;
    for (const f of findings) {
        if (f.severity === 'removed') {
            hours += 0.5;
        }
        else if (f.severity === 'deprecated_stable') {
            hours += 0.25;
        }
        else {
            hours += 0.1;
        }
    }
    return Math.round(hours * 100) / 100;
}
// ---------------------------------------------------------------------------
// Report builder
// ---------------------------------------------------------------------------
/** Build a DeprecationReport from raw findings. */
export function buildDeprecationReport(projectId, ecosystem, findings) {
    const bySevertiy = {
        removed: 0,
        deprecated_stable: 0,
        deprecated_upcoming: 0,
    };
    const fileCounts = {};
    for (const f of findings) {
        bySevertiy[f.severity] += 1;
        fileCounts[f.file] = (fileCounts[f.file] ?? 0) + 1;
    }
    const mostAffectedFiles = Object.entries(fileCounts)
        .sort(([, a], [, b]) => b - a)
        .slice(0, 5)
        .map(([file]) => file);
    return {
        projectId,
        timestamp: new Date().toISOString(),
        ecosystem,
        findings,
        totalFindings: findings.length,
        bySevertiy,
        mostAffectedFiles,
        techDebtHours: estimateTechDebt(findings),
    };
}
// ---------------------------------------------------------------------------
// Orchestrator
// ---------------------------------------------------------------------------
/**
 * Detect deprecated API usage in the project's source files.
 */
export async function detectDeprecations(projectPath, projectId, ecosystem) {
    const patterns = await loadDeprecationPatterns(ecosystem);
    const findings = await scanForDeprecations(projectPath, patterns);
    return buildDeprecationReport(projectId, ecosystem, findings);
}
//# sourceMappingURL=index.js.map