module.exports = {
  apps: [
    {
      name: 'stock-ingestion',
      script: './data-ingestion/dist/index.js',
      instances: 1,
      autorestart: true,
      watch: false,
      max_memory_restart: '1G',
      env: {
        NODE_ENV: 'production',
        PORT: 2001
      },
      env_development: {
        NODE_ENV: 'development',
        PORT: 2001
      }
    },
    {
      name: 'stock-pipeline',
      script: './data-pipeline/dist/index.js',
      instances: 1,
      autorestart: true,
      watch: false,
      max_memory_restart: '1G',
      env: {
        NODE_ENV: 'production',
        PORT: 2002
      },
      env_development: {
        NODE_ENV: 'development',
        PORT: 2002
      }
    },
    {
      name: 'stock-api',
      script: './web-api/dist/index.js',
      instances: 2,
      autorestart: true,
      watch: false,
      max_memory_restart: '1G',
      exec_mode: 'cluster',
      env: {
        NODE_ENV: 'production',
        PORT: 2003
      },
      env_development: {
        NODE_ENV: 'development',
        PORT: 2003
      }
    }
  ],

  deploy: {
    production: {
      user: 'deploy',
      host: 'production-server',
      ref: 'origin/master',
      repo: 'git@github.com:username/stock-bot.git',
      path: '/var/www/stock-bot',
      'post-deploy': 'cd apps/stock && npm install && npm run build && pm2 reload ecosystem.config.js --env production'
    },
    staging: {
      user: 'deploy',
      host: 'staging-server',
      ref: 'origin/develop',
      repo: 'git@github.com:username/stock-bot.git',
      path: '/var/www/stock-bot-staging',
      'post-deploy': 'cd apps/stock && npm install && npm run build && pm2 reload ecosystem.config.js --env development'
    }
  }
};