module.exports = {
  apps: [
    {
      name: 'ping-pong-1v1-server',
      cwd: __dirname,

      script: 'src/index.js',
      interpreter: 'node',

      // Cluster mode: one worker per logical CPU core.
      // Each worker gets its own event loop so physics ticks no longer
      // compete for a single thread.  Cross-worker WS routing is handled
      // via Redis Pub/Sub (src/ipc.js) — requires REDIS_URL to be set.
      instances: 'max',
      exec_mode: 'cluster',

      autorestart: true,
      watch: false,

      // Raise per-worker ceiling; total RAM = 300 M × instances.
      max_memory_restart: '300M',

      restart_delay: 5000,
      max_restarts: 10,
      min_uptime: '10s',

      // Give workers time to finish open matches on graceful shutdown.
      kill_timeout: 10000,
      wait_ready: false,

      env: {
        NODE_ENV: 'development',
      },

      env_production: {
        NODE_ENV: 'production',
      },

      error_file: './logs/ping-pong-1v1-server-error.log',
      out_file:   './logs/ping-pong-1v1-server-out.log',
      log_date_format: 'YYYY-MM-DD HH:mm:ss',

      // Merge stdout + stderr into one log file (optional, easier to tail).
      merge_logs: true,
    },
  ],
};