// tools/migrate-tech/core-handlers.ts — Handlers: analyze | map | plan | strategy | validate
import { t } from '../../i18n/index.js';
import { buildStackAnalysis, scoreMigratableComponents, buildEquivalenceMap, generateMigrationPlan, recommendMigrationStrategy, generateParityValidation, } from '../../engine/migration/index.js';
export function handleAnalyze(args) {
    const components = scoreMigratableComponents([
        {
            id: 'app-core',
            name: 'Application Core',
            path: args.projectPath ?? './src',
            type: 'module',
            cyclomaticComplexity: 8,
            couplingScore: 5,
            dependsOn: [],
            dependents: ['api-handler'],
            linesOfCode: 400,
        },
        {
            id: 'api-handler',
            name: 'API Handler',
            path: args.projectPath ? `${args.projectPath}/api` : './src/api',
            type: 'handler',
            cyclomaticComplexity: 12,
            couplingScore: 6,
            dependsOn: ['app-core'],
            dependents: [],
            linesOfCode: 250,
        },
    ]);
    const data = buildStackAnalysis({
        language: args.sourceStack ?? 'unknown',
        framework: args.sourceStack ?? 'unknown',
        components: [],
        entryPoints: [{ type: 'http', name: 'REST API', description: 'Main HTTP entry point' }],
        externalIntegrations: [],
        migratableComponents: components,
        hasTests: false,
    });
    const warnings = data.riskFlags;
    return {
        action: 'analyze',
        data,
        message: t('tools.migrate_tech.analyzeSuccess'),
        warnings,
        savedTo: args.projectId ? `data/projects/${args.projectId}/migration-analysis.json` : undefined,
    };
}
export function handleMap(args) {
    const source = args.sourceStack ?? 'unknown';
    const target = args.targetStack ?? 'unknown';
    const data = buildEquivalenceMap(source, target);
    const warnings = data.unsupportedPairs.length > 0
        ? [`${data.unsupportedPairs.length} equivalence(s) require manual mapping`]
        : [];
    return {
        action: 'map',
        data,
        message: t('tools.migrate_tech.mapSuccess'),
        warnings,
        savedTo: args.projectId ? `data/projects/${args.projectId}/migration-map.json` : undefined,
    };
}
export function handlePlan(args) {
    const components = scoreMigratableComponents([
        {
            id: 'utils',
            name: 'Utils',
            path: './src/utils',
            type: 'util',
            cyclomaticComplexity: 3,
            couplingScore: 1,
            dependsOn: [],
            dependents: ['service'],
            linesOfCode: 100,
        },
        {
            id: 'service',
            name: 'Service',
            path: './src/service',
            type: 'service',
            cyclomaticComplexity: 10,
            couplingScore: 4,
            dependsOn: ['utils'],
            dependents: ['handler'],
            linesOfCode: 300,
        },
        {
            id: 'handler',
            name: 'Handler',
            path: './src/handler',
            type: 'handler',
            cyclomaticComplexity: 6,
            couplingScore: 3,
            dependsOn: ['service'],
            dependents: [],
            linesOfCode: 150,
        },
    ]);
    const data = generateMigrationPlan({
        sourceStack: args.sourceStack ?? 'unknown',
        targetStack: args.targetStack ?? 'unknown',
        components,
        hasTests: false,
    });
    const warnings = [];
    if (data.circularDependencies.length > 0) {
        warnings.push(`${data.circularDependencies.length} circular dependency cycles detected — resolve before migrating`);
    }
    return {
        action: 'plan',
        data,
        message: t('tools.migrate_tech.planSuccess'),
        warnings,
    };
}
export function handleStrategy(_args) {
    const data = recommendMigrationStrategy({
        componentCount: 15,
        hasActiveUsers: true,
        hasHighSla: false,
        hasCriticalData: false,
        migratableComponents: [],
        entryPoints: ['/api/users', '/api/orders', '/api/products'],
    });
    return {
        action: 'strategy',
        data,
        message: t('tools.migrate_tech.strategySuccess'),
        warnings: [],
    };
}
export function handleValidate(args) {
    const component = args.component ?? 'Unknown Component';
    const data = generateParityValidation({
        component,
        endpoints: ['GET /api/resource', 'POST /api/resource', 'DELETE /api/resource/:id'],
        observedDifferences: [],
    });
    return {
        action: 'validate',
        data,
        message: t('tools.migrate_tech.validateSuccess'),
        warnings: [],
    };
}
//# sourceMappingURL=core-handlers.js.map