// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// engine/infrastructure/component-mapper.ts — Map InfraSignals to InfraComponents (SPEC-171)
import { getTerraformVersion } from '../../config/version-defaults.js';
/** Normalize environment string to a valid key: 'dev' | 'staging' | 'prod'. Defaults to 'dev'. */
export function resolveEnvironment(environment) {
    return environment in { dev: 1, staging: 1, prod: 1 } ? environment : 'dev';
}
function resolveDatabase(technology) {
    switch (technology) {
        case 'postgres':
            return {
                kind: 'rds',
                name: 'postgres-db',
                sizeByEnv: { dev: 'db.t3.micro', staging: 'db.t3.small', prod: 'db.t3.medium' },
                properties: { engine: 'postgres', version: getTerraformVersion('postgres-engine') },
            };
        case 'mysql':
            return {
                kind: 'rds',
                name: 'mysql-db',
                sizeByEnv: { dev: 'db.t3.micro', staging: 'db.t3.small', prod: 'db.t3.medium' },
                properties: { engine: 'mysql', version: '8.0' },
            };
        case 'mongodb':
            return {
                kind: 'generic-database',
                name: 'mongo-db',
                sizeByEnv: { dev: 'M0', staging: 'M10', prod: 'M30' },
                properties: { provider: 'mongodb-atlas' },
            };
        default:
            return {
                kind: 'generic-database',
                name: 'primary-db',
                sizeByEnv: { dev: 'small', staging: 'medium', prod: 'large' },
            };
    }
}
function resolveCache(technology) {
    if (technology === 'redis') {
        return {
            kind: 'redis',
            name: 'redis-cache',
            sizeByEnv: { dev: 'cache.t3.micro', staging: 'cache.t3.small', prod: 'cache.t3.medium' },
        };
    }
    return {
        kind: 'generic-cache',
        name: 'cache',
        sizeByEnv: { dev: 'small', staging: 'medium', prod: 'large' },
    };
}
function resolveQueue(technology) {
    if (technology === 'sqs') {
        return {
            kind: 'sqs',
            name: 'message-queue',
            sizeByEnv: { dev: 'standard', staging: 'standard', prod: 'standard' },
        };
    }
    return {
        kind: 'generic-queue',
        name: 'message-queue',
        sizeByEnv: { dev: 'small', staging: 'medium', prod: 'large' },
    };
}
function resolveStorage(technology) {
    if (technology === 's3') {
        return {
            kind: 's3',
            name: 'object-storage',
            sizeByEnv: { dev: 'standard', staging: 'standard', prod: 'standard' },
        };
    }
    return {
        kind: 'generic-storage',
        name: 'file-storage',
        sizeByEnv: { dev: 'small', staging: 'medium', prod: 'large' },
    };
}
function resolveApi(technology) {
    if (technology === 'lambda') {
        return {
            kind: 'lambda',
            name: 'api-function',
            sizeByEnv: { dev: '128MB', staging: '256MB', prod: '512MB' },
        };
    }
    if (technology === 'ecs') {
        return {
            kind: 'ecs',
            name: 'api-service',
            sizeByEnv: { dev: '256 CPU / 512 MB', staging: '512 CPU / 1GB', prod: '1024 CPU / 2GB' },
        };
    }
    return {
        kind: 'railway-service',
        name: 'api-service',
        sizeByEnv: { dev: 'starter', staging: 'pro', prod: 'pro' },
    };
}
function signalToSpec(signal) {
    switch (signal.type) {
        case 'database':
            return resolveDatabase(signal.technology);
        case 'cache':
            return resolveCache(signal.technology);
        case 'queue':
            return resolveQueue(signal.technology);
        case 'storage':
            return resolveStorage(signal.technology);
        case 'api':
            return resolveApi(signal.technology);
        case 'kubernetes':
            return {
                kind: 'k8s-deployment',
                name: 'app-deployment',
                sizeByEnv: { dev: 'small', staging: 'medium', prod: 'large' },
            };
        case 'railway':
            return {
                kind: 'railway-service',
                name: 'railway-app',
                sizeByEnv: { dev: 'starter', staging: 'pro', prod: 'pro' },
            };
        case 'serverless':
            return {
                kind: 'lambda',
                name: 'serverless-function',
                sizeByEnv: { dev: '128MB', staging: '256MB', prod: '512MB' },
            };
        case 'cdn':
            return {
                kind: 'cdn-cloudfront',
                name: 'cdn-distribution',
                sizeByEnv: { dev: 'standard', staging: 'standard', prod: 'standard' },
            };
    }
}
/**
 * Convert detected signals to concrete InfraComponent instances.
 * Deduplicates by component kind — only the first signal per kind is used.
 */
export function mapSignalsToComponents(signals, environment) {
    const env = resolveEnvironment(environment);
    const seenKinds = new Set();
    const components = [];
    for (const signal of signals) {
        const spec = signalToSpec(signal);
        if (seenKinds.has(spec.kind)) {
            continue;
        }
        seenKinds.add(spec.kind);
        components.push({
            kind: spec.kind,
            name: spec.name,
            size: spec.sizeByEnv[env] ?? spec.sizeByEnv.dev ?? 'small',
            estimatedMonthlyCostUsd: 0, // filled by cost-estimator
            properties: spec.properties ?? {},
        });
    }
    return components;
}
//# sourceMappingURL=component-mapper.js.map