// tools/migrate-tech.ts — Tech migration planning tool (SPEC-028a + SPEC-028b + SPEC-050 + SPEC-054)
// Actions: analyze | map | plan | strategy | validate | analyze-db | map-db | plan-db
//          analyze-services | map-services | plan-services | validate-service
//          rollback-plan | checkpoint | rollback | feature-flags | status
//          webpack-to-vite | vite6-to-vite7 | detect-pending
import { handleAnalyze, handleMap, handlePlan, handleStrategy, handleValidate, } from './migrate-tech/core-handlers.js';
import { handleAnalyzeDb, handleMapDb, handlePlanDb, handleAnalyzeServices, handleMapServices, handlePlanServices, handleValidateService, } from './migrate-tech/data-handlers.js';
import { handleRollbackPlan, handleCheckpoint, handleRollback, handleFeatureFlags, handleStatus, } from './migrate-tech/advanced-handlers.js';
import { handleWebpackToVite, handleVite6ToVite7 } from './migrate-tech/build-tool-handlers.js';
import { handleDetectPending } from './migrate-tech/detect-pending-handler.js';
// --- Action dispatch (sync handlers) ---
const SYNC_ACTION_HANDLERS = {
    analyze: handleAnalyze,
    map: handleMap,
    plan: handlePlan,
    strategy: handleStrategy,
    validate: handleValidate,
    'analyze-db': handleAnalyzeDb,
    'map-db': handleMapDb,
    'plan-db': handlePlanDb,
    'analyze-services': handleAnalyzeServices,
    'map-services': handleMapServices,
    'plan-services': handlePlanServices,
    'validate-service': handleValidateService,
    'rollback-plan': handleRollbackPlan,
    checkpoint: handleCheckpoint,
    rollback: handleRollback,
    'feature-flags': handleFeatureFlags,
    status: handleStatus,
};
// SPEC-050 S4 + SPEC-054 S4: Async migration handlers
const ASYNC_ACTION_HANDLERS = {
    'webpack-to-vite': handleWebpackToVite,
    'vite6-to-vite7': handleVite6ToVite7,
    'detect-pending': handleDetectPending,
};
// --- Format output ---
function formatResult(result) {
    const lines = [`## migrate_tech: ${result.action}`, '', result.message, ''];
    if (result.warnings.length > 0) {
        lines.push('### Warnings');
        result.warnings.forEach((w) => lines.push(`- ${w}`));
        lines.push('');
    }
    if (result.savedTo) {
        lines.push(`_Saved to: \`${result.savedTo}\`_`);
        lines.push('');
    }
    lines.push('### Result');
    lines.push('');
    lines.push('```json');
    lines.push(JSON.stringify(result.data, null, 2));
    lines.push('```');
    return lines.join('\n');
}
// --- Main handler ---
export async function handleMigrateTech(args) {
    const asyncHandler = ASYNC_ACTION_HANDLERS[args.action];
    if (asyncHandler !== undefined) {
        const result = await asyncHandler(args);
        return { content: [{ type: 'text', text: formatResult(result) }] };
    }
    const syncHandler = SYNC_ACTION_HANDLERS[args.action];
    /* v8 ignore start */
    if (syncHandler === undefined) {
        return {
            content: [{ type: 'text', text: `Unknown action: ${args.action}` }],
            isError: true,
        };
    }
    /* v8 ignore stop */
    const result = syncHandler(args);
    return {
        content: [{ type: 'text', text: formatResult(result) }],
    };
}
//# sourceMappingURL=migrate-tech.js.map