// engine/migration/service-migrator-planner.ts — Migration planning + validation checklist
// Handles risk-ordered migration planning and per-service behavioral validation
import { VALIDATION_CHECK_TEMPLATES } from './service-migrator-catalogs.js';
export function planServicesMigration(services) {
    // Priority: stateless first, then stateful-replayable, then stateful-critical
    const riskOrder = {
        stateless: 1,
        'stateful-replayable': 2,
        'stateful-critical': 3,
    };
    const sorted = [...services].sort((a, b) => riskOrder[a.riskLevel] - riskOrder[b.riskLevel]);
    const orderedServices = sorted.map((svc, idx) => ({
        serviceId: svc.id,
        serviceName: svc.name,
        serviceType: svc.type,
        migrationOrder: idx + 1,
        rationale: svc.riskLevel === 'stateless'
            ? 'Stateless service — safest to migrate first; no data loss risk'
            : svc.riskLevel === 'stateful-replayable'
                ? 'Stateful with replay capability — migrate after stateless; use dual-write during transition'
                : 'Stateful critical — migrate last; requires zero-downtime strategy and full backup',
    }));
    const stateless = sorted.filter((s) => s.riskLevel === 'stateless').map((s) => s.id);
    const replayable = sorted.filter((s) => s.riskLevel === 'stateful-replayable').map((s) => s.id);
    const critical = sorted.filter((s) => s.riskLevel === 'stateful-critical').map((s) => s.id);
    const phases = [];
    if (stateless.length > 0) {
        phases.push({
            phase: 1,
            services: stateless,
            description: 'Stateless services (caches, auth, observability)',
        });
    }
    if (replayable.length > 0) {
        phases.push({
            phase: 2,
            services: replayable,
            description: 'Stateful replayable services (message queues)',
        });
    }
    if (critical.length > 0) {
        phases.push({
            phase: 3,
            services: critical,
            description: 'Stateful critical services (object storage, permanent data)',
        });
    }
    const estimatedWeeks = Math.ceil(services.length * 0.5) + (critical.length > 0 ? 2 : 0);
    return {
        orderedServices,
        phases,
        totalServices: services.length,
        estimatedWeeks,
        generatedAt: new Date().toISOString(),
    };
}
export function generateServiceValidationChecklist(service) {
    const template = VALIDATION_CHECK_TEMPLATES.find((t) => t.serviceType === service.type);
    const checks = template?.checks.map((c) => ({
        ...c,
        expectedValue: 'Define from current system baseline',
    })) ?? [];
    return {
        serviceId: service.id,
        serviceName: service.name,
        checks,
        generatedAt: new Date().toISOString(),
    };
}
//# sourceMappingURL=service-migrator-planner.js.map