import { detectDeprecations } from '../engine/deprecation-scanner/index.js';
import { detectEcosystem } from '../engine/stack-auditor/manifest-reader.js';
import { hashProjectPath } from '../storage/base-store.js';
// ---------------------------------------------------------------------------
// Formatters
// ---------------------------------------------------------------------------
function formatSummary(report) {
    const { ecosystem, findings, totalFindings, bySevertiy, mostAffectedFiles, techDebtHours } = report;
    const lines = [
        `## Deprecation Report — ${ecosystem}`,
        `**Total Findings**: ${totalFindings}`,
        `**Estimated Tech Debt**: ${techDebtHours}h`,
        '',
        '### By Severity',
        `- Removed APIs: ${bySevertiy.removed}`,
        `- Deprecated (stable): ${bySevertiy.deprecated_stable}`,
        `- Deprecated (upcoming): ${bySevertiy.deprecated_upcoming}`,
    ];
    if (mostAffectedFiles.length > 0) {
        lines.push('', '### Most Affected Files');
        mostAffectedFiles.forEach((f) => lines.push(`- ${f}`));
    }
    if (findings.length > 0) {
        lines.push('', '### Findings');
        findings.slice(0, 20).forEach((f) => {
            lines.push(`- **${f.apiName}** in \`${f.file}\`:${f.line} [${f.severity}]`);
            lines.push(`  Replace with: ${f.replacement}`);
        });
        if (findings.length > 20) {
            lines.push(`- ...and ${findings.length - 20} more`);
        }
    }
    else {
        lines.push('', 'No deprecated API usage found.');
    }
    return lines.join('\n');
}
// ---------------------------------------------------------------------------
// Handler
// ---------------------------------------------------------------------------
export async function handleDetectDeprecations(args) {
    const projectId = hashProjectPath(args.projectPath);
    const ecosystem = args.ecosystem ?? (await detectEcosystem(args.projectPath));
    const report = await detectDeprecations(args.projectPath, projectId, ecosystem);
    const format = args.format ?? 'summary';
    const text = format === 'json' ? JSON.stringify(report, null, 2) : formatSummary(report);
    return { content: [{ type: 'text', text }] };
}
//# sourceMappingURL=detect-deprecations.js.map