import { auditSchemaParity } from '../engine/schema-parity-auditor/index.js';
import { formatSuccess, formatError, toolResult } from './response-helpers.js';
/**
 * Scans all register-*.ts files in the project for Zod/TypeScript optional parity issues.
 * Returns a structured report with discrepancies and suggested fixes.
 */
export async function handleAuditSchemaParity(args) {
    const { projectPath } = args;
    if (!projectPath || projectPath.trim() === '') {
        return toolResult(formatError('projectPath is required', 'Provide the absolute path to the project root.'), undefined, true);
    }
    const result = await auditSchemaParity(projectPath.trim());
    const bodyLines = [
        `Total optional fields scanned: ${String(result.totalOptionalFields)}`,
        `Discrepancies found: ${String(result.discrepancies.length)}`,
    ];
    if (result.discrepancies.length > 0) {
        bodyLines.push('', 'Discrepancies:', '--------------');
        for (const d of result.discrepancies) {
            bodyLines.push(`[${d.severity.toUpperCase()}] ${d.toolName} -> ${d.fieldName}`);
            bodyLines.push(`  Register: ${d.registerFile}`);
            bodyLines.push(`  Type:     ${d.typeFile}`);
            bodyLines.push(`  Fix:      ${d.suggestedFix}`);
            bodyLines.push('');
        }
    }
    bodyLines.push('', result.summary);
    const text = formatSuccess('Schema Parity Audit Report', bodyLines.join('\n'));
    return toolResult(text, { ...result }, false);
}
//# sourceMappingURL=audit-schema-parity-handler.js.map