// tools/transform-code-handler.ts — Handler for transform_code MCP tool (AC-09).
// Synchronous handler that wraps the transform engine.
import { TRANSFORM_INTENTS, } from '../types/index.js';
import { executeTransform } from '../engine/code-transforms/transform-engine.js';
/**
 * Handle transform_code tool invocation.
 * Validates input, delegates to executeTransform, and formats the response.
 */
export function handleTransformCode(args) {
    // Validate intent
    if (!TRANSFORM_INTENTS.includes(args.intent)) {
        return {
            content: [
                {
                    type: 'text',
                    text: `Invalid intent '${args.intent}'. Valid intents: ${TRANSFORM_INTENTS.join(', ')}`,
                },
            ],
            isError: true,
        };
    }
    const result = executeTransform({
        source: args.source,
        intent: args.intent,
        options: args.options ?? {},
    });
    if (!result.success) {
        return {
            content: [
                {
                    type: 'text',
                    /* v8 ignore next 1 -- defensive: executeTransform always sets error when !success */
                    text: `Transform failed: ${result.error ?? 'Unknown error'}`,
                },
            ],
            isError: true,
        };
    }
    const summary = [
        `## Transform: ${args.intent}`,
        '',
        `**Changes:** ${String(result.changes.length)}`,
        `**Duration:** ${result.durationMs.toFixed(2)}ms`,
        '',
    ];
    if (result.changes.length > 0) {
        summary.push('### Changes');
        for (const change of result.changes) {
            summary.push(`- Line ${String(change.line)}: ${change.description}`);
        }
        summary.push('');
    }
    summary.push('### Transformed Code', '```typescript', result.transformed, '```');
    return {
        content: [{ type: 'text', text: summary.join('\n') }],
    };
}
//# sourceMappingURL=transform-code-handler.js.map