// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// engine/infrastructure/docker-compose-generator.ts — Docker Compose generator (SPEC-171)
import { getDockerTag } from '../../config/version-defaults.js';
function renderHeader() {
    return `# docker-compose.yml — Generated by Planu generate_infrastructure (SPEC-171)
# Local development environment matching production topology.
# Usage: docker compose up -d

services:
`;
}
function renderDatabase(component) {
    const dbName = component.name.replace(/-/g, '_');
    const engine = (component.properties.engine ??
        component.properties.technology ??
        'postgres').toLowerCase();
    if (engine === 'mysql' || engine === 'mariadb') {
        return `  ${component.name}:
    image: ${engine}:${getDockerTag('mysql')}
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${dbName}
      MYSQL_USER: dbadmin
      MYSQL_PASSWORD: \${DB_PASSWORD:-changeme}
      MYSQL_ROOT_PASSWORD: \${DB_ROOT_PASSWORD:-changeme}
    ports:
      - "3306:3306"
    volumes:
      - ${component.name}_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "${engine}", "-u", "dbadmin", "-p\${DB_PASSWORD:-changeme}", "-e", "SELECT 1"]
      interval: 10s
      timeout: 5s
      retries: 5

`;
    }
    if (engine === 'mongo' || engine === 'mongodb') {
        return `  ${component.name}:
    image: mongo:${getDockerTag('mongo')}
    restart: unless-stopped
    environment:
      MONGO_INITDB_DATABASE: ${dbName}
      MONGO_INITDB_ROOT_USERNAME: dbadmin
      MONGO_INITDB_ROOT_PASSWORD: \${DB_PASSWORD:-changeme}
    ports:
      - "27017:27017"
    volumes:
      - ${component.name}_data:/data/db
    healthcheck:
      test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
      interval: 10s
      timeout: 5s
      retries: 5

`;
    }
    // Default: postgres
    return `  ${component.name}:
    image: postgres:${getDockerTag('postgres')}
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${dbName}
      POSTGRES_USER: dbadmin
      POSTGRES_PASSWORD: \${DB_PASSWORD:-changeme}
    ports:
      - "5432:5432"
    volumes:
      - ${component.name}_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U dbadmin"]
      interval: 10s
      timeout: 5s
      retries: 5

`;
}
function renderRedis(component) {
    return `  ${component.name}:
    image: redis:${getDockerTag('redis')}
    restart: unless-stopped
    ports:
      - "6379:6379"
    command: redis-server --appendonly yes
    volumes:
      - ${component.name}_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

`;
}
function renderQueue(component) {
    return `  ${component.name}:
    image: rabbitmq:${getDockerTag('rabbitmq')}
    restart: unless-stopped
    environment:
      RABBITMQ_DEFAULT_USER: admin
      RABBITMQ_DEFAULT_PASS: \${RABBITMQ_PASSWORD:-changeme}
    ports:
      - "5672:5672"
      - "15672:15672"
    volumes:
      - ${component.name}_data:/var/lib/rabbitmq
    healthcheck:
      test: ["CMD", "rabbitmq-diagnostics", "ping"]
      interval: 15s
      timeout: 10s
      retries: 5

`;
}
function renderStorage(component) {
    return `  ${component.name}:
    image: minio/minio:${getDockerTag('minio')}
    restart: unless-stopped
    environment:
      MINIO_ROOT_USER: \${MINIO_USER:-minioadmin}
      MINIO_ROOT_PASSWORD: \${MINIO_PASSWORD:-changeme}
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - ${component.name}_data:/data
    command: server /data --console-address ":9001"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

`;
}
function renderVolumes(components) {
    const volumeKinds = [
        'rds',
        'generic-database',
        'redis',
        'generic-cache',
        'sqs',
        'generic-queue',
        's3',
        'generic-storage',
    ];
    const volumeComponents = components.filter((c) => volumeKinds.includes(c.kind));
    if (volumeComponents.length === 0) {
        return '';
    }
    const volumeLines = volumeComponents.map((c) => `  ${c.name}_data:`).join('\n');
    return `\nvolumes:\n${volumeLines}\n`;
}
function renderService(component) {
    switch (component.kind) {
        case 'rds':
        case 'generic-database':
        case 'supabase':
            return renderDatabase(component);
        case 'redis':
        case 'generic-cache':
            return renderRedis(component);
        case 'generic-queue':
        case 'sqs':
            return renderQueue(component);
        case 's3':
        case 'generic-storage':
            return renderStorage(component);
        case 'ecs':
        case 'lambda':
        case 'railway-service':
        case 'k8s-deployment':
        case 'k8s-service':
        case 'k8s-ingress':
        case 'cdn-cloudfront':
            return '';
    }
}
/**
 * Generate a docker-compose.yml for local development.
 */
export function generateDockerCompose(components) {
    const localComponents = components.filter((c) => [
        'rds',
        'supabase',
        'redis',
        'sqs',
        's3',
        'generic-database',
        'generic-cache',
        'generic-queue',
        'generic-storage',
    ].includes(c.kind));
    const services = localComponents.map(renderService).join('');
    const volumes = renderVolumes(localComponents);
    const content = renderHeader() + services + volumes;
    return {
        format: 'docker-compose',
        filename: 'docker-compose.yml',
        content,
    };
}
//# sourceMappingURL=docker-compose-generator.js.map