import { analyzeDependencyHealth } from '../engine/dependency-health.js';
import { formatSuccess, formatError, toolResult } from './response-helpers.js';
export async function handleDependencyHealth(args) {
    if (!args.projectPath.trim()) {
        return toolResult(formatError('projectPath is required'), undefined, true);
    }
    const result = await analyzeDependencyHealth({
        projectPath: args.projectPath,
        ecosystem: args.ecosystem ?? 'npm',
    });
    const lines = [
        `Score: ${String(result.score)}/100`,
        `Bloat score: ${String(result.bloatScore)}`,
        '',
        `Unused: ${String(result.unused.length)}`,
        `Missing: ${String(result.missing.length)}`,
        `Peer conflicts: ${String(result.peerConflicts.length)}`,
        `Outdated: ${String(result.outdated.length)}`,
        `Duplicated: ${String(result.duplicated.length)}`,
        '',
        'Recommendations:',
        ...result.recommendations.map((r) => `  - ${r}`),
    ];
    if (result.unused.length > 0) {
        lines.push('', 'Unused packages:');
        for (const u of result.unused) {
            lines.push(`  - ${u.name}@${u.version} — ${u.suggestion}`);
        }
    }
    if (result.missing.length > 0) {
        lines.push('', 'Missing packages:');
        for (const m of result.missing) {
            lines.push(`  - ${m.name} (imported in ${String(m.importers.length)} file(s))`);
        }
    }
    if (result.peerConflicts.length > 0) {
        lines.push('', 'Peer conflicts:');
        for (const p of result.peerConflicts) {
            lines.push(`  - ${p.package}: expected ${p.expected}, found ${p.found}`);
        }
    }
    if (result.outdated.length > 0) {
        lines.push('', 'Outdated packages:');
        for (const o of result.outdated) {
            lines.push(`  - ${o.name}: ${o.current} → ${o.latest} (${o.severity})`);
        }
    }
    if (result.duplicated.length > 0) {
        lines.push('', 'Duplicated packages:');
        for (const d of result.duplicated) {
            lines.push(`  - ${d.name}: ${d.versions.join(', ')}`);
        }
    }
    return toolResult(formatSuccess('Dependency Health', lines.join('\n')), result);
}
//# sourceMappingURL=dependency-health.js.map