import { detectDuplication } from '../engine/detect-duplication.js';
import { formatSuccess, formatError, toolResult } from './response-helpers.js';
export async function handleDetectDuplication(args) {
    if (!args.projectPath.trim()) {
        return toolResult(formatError('projectPath is required'), undefined, true);
    }
    const result = await detectDuplication(args);
    if (result.clusters.length === 0) {
        return toolResult(formatSuccess('No Duplication Detected', 'No duplicate code blocks found matching the criteria.'), result);
    }
    const lines = [
        `Duplicate Code Detection — ${args.projectPath}`,
        `Total clusters: ${String(result.totalClusters)}`,
        `Files affected: ${String(result.totalFilesAffected)}`,
        `Overall severity: ${result.severity.toUpperCase()}`,
        '',
    ];
    for (const cluster of result.clusters) {
        lines.push(`--- ${cluster.id} (${cluster.severity.toUpperCase()}) — ${String(cluster.lineCount)} lines, ${String(cluster.similarity)}% similarity ---`);
        for (const file of cluster.files) {
            lines.push(`  ${file.path}:${String(file.startLine)}-${String(file.endLine)}`);
        }
        lines.push(`  Suggestion: ${cluster.suggestion}`);
        lines.push('');
    }
    return toolResult(formatSuccess('Duplication Report', lines.join('\n')), result);
}
//# sourceMappingURL=detect-duplication.js.map