// engine/migration/equivalence-mapper.ts — Tech equivalence mapping (SPEC-028a)
// Maps source stack libs to target stack equivalents
// --- Known equivalence knowledge base ---
const JAVA_TO_GO = [
    {
        sourceLib: 'Spring MVC',
        targetLib: 'net/http + chi',
        category: 'framework',
        status: 'partial',
        differences: [
            'Spring DI via @Autowired — Go uses manual constructor injection',
            'Spring AOP not available in Go — cross-cutting concerns via middleware',
        ],
        notes: 'Consider Gin or Echo for more batteries-included alternatives',
    },
    {
        sourceLib: 'JPA / Hibernate',
        targetLib: 'GORM',
        category: 'database',
        status: 'partial',
        differences: [
            'JPA lazy loading not available in GORM — all relations explicit',
            'Hibernate L2 cache not equivalent — use Redis manually',
        ],
    },
    {
        sourceLib: 'JUnit 5',
        targetLib: 'testing (stdlib) + testify',
        category: 'testing',
        status: 'exact',
        differences: [],
    },
    {
        sourceLib: 'Log4j / SLF4J',
        targetLib: 'zerolog / zap',
        category: 'library',
        status: 'partial',
        differences: ['Structured logging differences in API surface'],
    },
    {
        sourceLib: 'Spring Security',
        targetLib: 'middleware + jwt-go',
        category: 'auth',
        status: 'manual',
        differences: [
            'No equivalent framework — implement auth middleware manually',
            'RBAC must be hand-coded or use Casbin',
        ],
    },
];
const PHP_TO_NODE = [
    {
        sourceLib: 'Laravel',
        targetLib: 'NestJS',
        category: 'framework',
        status: 'partial',
        differences: [
            'Laravel Eloquent ORM → TypeORM / Prisma',
            'Artisan CLI → NestJS CLI',
            'Blade templates → not applicable for API-only migration',
        ],
    },
    {
        sourceLib: 'Eloquent ORM',
        targetLib: 'Prisma',
        category: 'database',
        status: 'exact',
        differences: ['API syntax differs significantly'],
        notes: 'TypeORM is closer to Eloquent in philosophy',
    },
    {
        sourceLib: 'PHPUnit',
        targetLib: 'Jest / Vitest',
        category: 'testing',
        status: 'exact',
        differences: [],
    },
    {
        sourceLib: 'Composer',
        targetLib: 'npm / pnpm',
        category: 'build',
        status: 'exact',
        differences: [],
    },
];
const PYTHON_DJANGO_TO_FASTAPI = [
    {
        sourceLib: 'Django',
        targetLib: 'FastAPI',
        category: 'framework',
        status: 'partial',
        differences: [
            'Django ORM → SQLAlchemy or Tortoise ORM',
            'Django admin panel has no FastAPI equivalent',
            'Django signals → event-based pattern or message queue',
        ],
    },
    {
        sourceLib: 'Django ORM',
        targetLib: 'SQLAlchemy (async)',
        category: 'database',
        status: 'partial',
        differences: ['Django QuerySet API differs from SQLAlchemy session'],
    },
    {
        sourceLib: 'pytest',
        targetLib: 'pytest',
        category: 'testing',
        status: 'exact',
        differences: [],
    },
    {
        sourceLib: 'Celery',
        targetLib: 'arq / dramatiq',
        category: 'queue',
        status: 'partial',
        differences: ['Task syntax and broker config differ'],
    },
];
const EXPRESS_TO_FASTIFY = [
    {
        sourceLib: 'Express',
        targetLib: 'Fastify',
        category: 'framework',
        status: 'partial',
        differences: [
            'Express middleware API differs from Fastify plugin/hook API',
            'Fastify schema validation built-in via Ajv',
            'Express req/res differs from Fastify request/reply',
        ],
    },
    {
        sourceLib: 'express-validator',
        targetLib: 'Fastify built-in schema validation',
        category: 'library',
        status: 'partial',
        differences: ['JSON Schema vs fluent validation API'],
    },
];
const KNOWLEDGE_BASE = {
    'java-go': JAVA_TO_GO,
    'php-node': PHP_TO_NODE,
    'php-typescript': PHP_TO_NODE,
    'python-fastapi': PYTHON_DJANGO_TO_FASTAPI,
    'express-fastify': EXPRESS_TO_FASTIFY,
    'express-hono': EXPRESS_TO_FASTIFY,
};
function normalizeStackKey(source, target) {
    const s = source.toLowerCase().replace(/[^a-z]/g, '-');
    const t = target.toLowerCase().replace(/[^a-z]/g, '-');
    return `${s}-${t}`;
}
function findPartialMatch(key) {
    const keys = Object.keys(KNOWLEDGE_BASE);
    for (const k of keys) {
        if (key.includes(k) || k.includes(key)) {
            /* v8 ignore start */
            return KNOWLEDGE_BASE[k] ?? [];
            /* v8 ignore stop */
        }
    }
    return [];
}
export function buildEquivalenceMap(sourceStack, targetStack) {
    const key = normalizeStackKey(sourceStack, targetStack);
    const entries = KNOWLEDGE_BASE[key] ?? findPartialMatch(key);
    const equivalences = entries.map((e) => ({
        originLib: e.sourceLib,
        originStack: sourceStack,
        targetLib: e.targetLib,
        targetStack,
        category: e.category,
        status: e.status,
        differences: e.differences,
        notes: e.notes,
    }));
    const unsupportedPairs = equivalences
        .filter((e) => e.status === 'manual' || e.status === 'none')
        .map((e) => `${e.originLib} → manual mapping required`);
    return {
        sourceStack,
        targetStack,
        equivalences,
        unsupportedPairs,
        generatedAt: new Date().toISOString(),
    };
}
export function getSupportedMigrationPairs() {
    return Object.keys(KNOWLEDGE_BASE);
}
//# sourceMappingURL=equivalence-mapper.js.map