// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// engine/infrastructure/railway-generator.ts — railway.toml generator (SPEC-171)
function renderRailwayService(component, env) {
    const isDatabase = ['rds', 'supabase', 'generic-database'].includes(component.kind);
    const isCache = ['redis', 'generic-cache'].includes(component.kind);
    if (isDatabase) {
        return `
[services.${component.name.replace(/-/g, '_')}]
  # Railway managed Postgres — provision via Railway dashboard
  # Connect via DATABASE_URL environment variable
`;
    }
    if (isCache) {
        return `
[services.${component.name.replace(/-/g, '_')}]
  # Railway managed Redis — provision via Railway dashboard
  # Connect via REDIS_URL environment variable
`;
    }
    return `
[services.${component.name.replace(/-/g, '_')}]
  startCommand = "node dist/index.js"
  healthcheckPath = "/health"
  healthcheckTimeout = 300

  [services.${component.name.replace(/-/g, '_')}.deploy]
    numReplicas = ${env === 'prod' ? 2 : 1}
    sleepApplication = ${env !== 'prod'}
    restartPolicyType = "ON_FAILURE"
    restartPolicyMaxRetries = 10
`;
}
function renderBuildConfig() {
    return `[build]
  builder = "NIXPACKS"
  buildCommand = "pnpm install --frozen-lockfile && pnpm build"

`;
}
function renderDeploy(env) {
    return `[deploy]
  startCommand = "node dist/index.js"
  healthcheckPath = "/health"
  healthcheckTimeout = 300
  numReplicas = ${env === 'prod' ? 2 : 1}
  sleepApplication = ${env !== 'prod'}
  restartPolicyType = "ON_FAILURE"
  restartPolicyMaxRetries = 10

`;
}
function renderEnvironments(env) {
    return `[environments.${env}]
  # Environment-specific overrides for ${env}
  # Add variables via Railway dashboard or railway variables set

`;
}
/**
 * Generate a railway.toml for Railway deployments.
 */
export function generateRailway(components, env) {
    const serviceBlocks = components
        .filter((c) => [
        'railway-service',
        'rds',
        'supabase',
        'redis',
        'generic-database',
        'generic-cache',
        'api',
        'ecs',
    ].includes(c.kind))
        .map((c) => renderRailwayService(c, env))
        .join('');
    const content = `# railway.toml — Generated by Planu generate_infrastructure (SPEC-171)\n` +
        `# Documentation: https://docs.railway.app/reference/config-as-code\n\n` +
        renderBuildConfig() +
        renderDeploy(env) +
        renderEnvironments(env) +
        (serviceBlocks || '# No additional services detected\n');
    return {
        format: 'railway',
        filename: 'railway.toml',
        content,
    };
}
//# sourceMappingURL=railway-generator.js.map