// engine/code-transforms/transform-engine.ts — Transform orchestrator (AC-01).
// Validates intent, dispatches to the correct transform implementation, measures timing.
import { TRANSFORM_INTENTS, } from '../../types/index.js';
import { renameSymbol } from './typescript/rename-symbol.js';
import { addTypes } from './typescript/add-types.js';
import { addErrorHandling } from './typescript/add-error-handling.js';
import { modernizeSyntax } from './typescript/modernize-syntax.js';
import { extractInterface } from './typescript/extract-interface.js';
import { addJSDoc } from './typescript/add-jsdoc.js';
/**
 * Execute a code transform based on the request intent.
 * Returns a TransformResult with the transformed source, changes list, and timing.
 */
export function executeTransform(request) {
    const start = performance.now();
    const fileName = request.fileName ?? 'input.ts';
    // Validate intent
    if (!TRANSFORM_INTENTS.includes(request.intent)) {
        return {
            success: false,
            transformed: request.source,
            changes: [],
            durationMs: performance.now() - start,
            error: `Unknown transform intent: '${request.intent}'. Valid intents: ${TRANSFORM_INTENTS.join(', ')}`,
        };
    }
    try {
        const result = dispatch(request.intent, request.source, request.options, fileName);
        return {
            success: true,
            transformed: result.transformed,
            changes: result.changes,
            durationMs: performance.now() - start,
        };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return {
            success: false,
            transformed: request.source,
            changes: [],
            durationMs: performance.now() - start,
            error: message,
        };
    }
}
function dispatch(intent, source, options, fileName) {
    switch (intent) {
        case 'rename-symbol':
            return renameSymbol(source, options, fileName);
        case 'add-types':
            return addTypes(source, options, fileName);
        case 'add-error-handling':
            return addErrorHandling(source, options, fileName);
        case 'modernize-syntax':
            return modernizeSyntax(source, options, fileName);
        case 'extract-interface':
            return extractInterface(source, options, fileName);
        case 'add-jsdoc':
            return addJSDoc(source, options, fileName);
        /* v8 ignore next 4 -- exhaustive check: unreachable thanks to TRANSFORM_INTENTS validation */
        default: {
            throw new Error(`Unhandled transform intent: ${String(intent)}`);
        }
    }
}
//# sourceMappingURL=transform-engine.js.map