import { fixSchemaParity } from '../engine/schema-parity-auditor/index.js';
import { formatSuccess, formatError, toolResult } from './response-helpers.js';
/**
 * Applies automatic fixes for Zod/TypeScript optional parity issues.
 * Adds "?" to TypeScript types for fields that are optional in Zod schemas.
 * When dryRun=true, shows what would change without writing files.
 */
export async function handleFixSchemaParity(args) {
    const { projectPath, dryRun } = args;
    if (!projectPath || projectPath.trim() === '') {
        return toolResult(formatError('projectPath is required', 'Provide the absolute path to the project root.'), undefined, true);
    }
    const result = await fixSchemaParity(projectPath.trim(), dryRun);
    const bodyLines = [
        dryRun ? 'Mode: DRY RUN (no files written)' : 'Mode: APPLIED',
        `Fixes: ${String(result.fixes.length)}`,
    ];
    if (result.fixes.length > 0) {
        bodyLines.push('', 'Changes:');
        for (const fix of result.fixes) {
            bodyLines.push(`- ${fix.description}`);
            if (fix.preview !== undefined) {
                bodyLines.push(`  Preview: ${fix.preview}`);
            }
        }
    }
    bodyLines.push('', result.summary);
    const title = dryRun ? 'Schema Parity Fix — Dry Run' : 'Schema Parity Fix — Applied';
    const text = formatSuccess(title, bodyLines.join('\n'));
    return toolResult(text, { ...result }, false);
}
//# sourceMappingURL=fix-schema-parity-handler.js.map