// tools/migrate-tech-advanced/service-handlers.ts — SPEC-028b service migration handlers
import { t } from '../../i18n/index.js';
import { analyzeExternalServices, buildServiceEquivalenceMap, planServicesMigration, generateServiceValidationChecklist, } from '../../engine/migration/index.js';
export function handleAnalyzeServices(args) {
    const dependencies = args.sourceStack ? args.sourceStack.split(',').map((d) => d.trim()) : [];
    const data = analyzeExternalServices({
        sourceStack: args.sourceStack ?? 'unknown',
        dependencies,
    });
    const warnings = [];
    if (data.criticalCount > 0) {
        warnings.push(`${data.criticalCount} critical (stateful) service(s) detected — plan migration last`);
    }
    if (data.totalDetected === 0) {
        warnings.push('No known external services detected — provide comma-separated dependencies in sourceStack for better detection');
    }
    return {
        action: 'analyze-services',
        data,
        message: t('tools.migrate_tech.analyzeServicesSuccess'),
        warnings,
        savedTo: args.projectId ? `data/projects/${args.projectId}/services-analysis.json` : undefined,
    };
}
export function handleMapServices(args) {
    const source = args.sourceStack ?? 'unknown';
    const target = args.targetStack ?? 'unknown';
    const analysisResult = analyzeExternalServices({ sourceStack: source, dependencies: [source] });
    const data = buildServiceEquivalenceMap(source, target, analysisResult.services);
    const warnings = [];
    if (data.unmappedServices.length > 0) {
        warnings.push(`${data.unmappedServices.length} service(s) have no built-in mapping: ${data.unmappedServices.join(', ')} — add adapters manually`);
    }
    return {
        action: 'map-services',
        data,
        message: t('tools.migrate_tech.mapServicesSuccess'),
        warnings,
        savedTo: args.projectId ? `data/projects/${args.projectId}/services-map.json` : undefined,
    };
}
export function handlePlanServices(args) {
    const source = args.sourceStack ?? 'unknown';
    const analysisResult = analyzeExternalServices({ sourceStack: source, dependencies: [source] });
    const data = planServicesMigration(analysisResult.services);
    const warnings = [];
    if (data.phases.some((p) => p.phase === 3)) {
        warnings.push('Critical stateful services detected — plan full data backup before phase 3');
    }
    return {
        action: 'plan-services',
        data,
        message: t('tools.migrate_tech.planServicesSuccess'),
        warnings,
    };
}
export function handleValidateService(args) {
    const serviceId = args.component ?? 'unknown-service';
    const service = {
        id: serviceId,
        name: serviceId,
        type: 'message-queue',
        provider: serviceId,
        critical: false,
        stateless: false,
        riskLevel: 'stateful-replayable',
        detectedIn: [],
    };
    const data = generateServiceValidationChecklist(service);
    return {
        action: 'validate-service',
        data,
        message: t('tools.migrate_tech.validateServiceSuccess'),
        warnings: [
            'Fill in "expectedValue" fields with actual baseline measurements from your current system',
        ],
    };
}
//# sourceMappingURL=service-handlers.js.map