module.exports = {
  apps: [
    {
      name: 'parentflow-backend-prod',
      cwd: './maternal-app/maternal-app-backend',
      script: 'dist/main.js',
      instances: 2,
      exec_mode: 'cluster',
      autorestart: true,
      watch: false,
      max_memory_restart: '500M',
      env: {
        NODE_ENV: 'production',
        API_PORT: 3020,
        PORT: 3020,
        // Dedicated PostgreSQL Server
        DATABASE_HOST: '10.0.0.207',
        DATABASE_PORT: 5432,
        DATABASE_NAME: 'parentflow',
        DATABASE_USER: 'postgres',
        DATABASE_PASSWORD: 'a3ppq',
        DATABASE_SSL: 'false',
        // Redis Docker on 10.0.0.240
        REDIS_HOST: 'localhost',
        REDIS_PORT: 6379,
        REDIS_PASSWORD: 'parentflow_redis_password_2024',
        // MongoDB Docker on 10.0.0.240
        MONGODB_URI: 'mongodb://parentflow_admin:parentflow_mongo_password_2024@localhost:27017/parentflow_ai_chat?authSource=admin',
        // MinIO Docker on 10.0.0.240
        MINIO_ENDPOINT: 'localhost',
        MINIO_PORT: 9000,
        MINIO_USE_SSL: false,
        MINIO_ACCESS_KEY: 'parentflow_minio_admin',
        MINIO_SECRET_KEY: 'parentflow_minio_password_2024',
        JWT_SECRET: '0OEe+ml/g8/w1LVUwOuot5EeqADcZXnu9eATnTEU91Ji4KL8A8rhN42e1TT0s4ksir/5OJkk5/mwW4VzMcHpaA==',
        JWT_REFRESH_SECRET: 'txk+0Olbuh0EPJd3Qq+zGfr+2ip6NtEHiq6iUDD/omBjt3ABO4ou7U/m9CgI4A8UlEU6cZmFkicdOB/QU+Og2g==',
        CORS_ORIGIN: 'https://web.parentflowapp.com,https://api.parentflowapp.com,http://localhost:3030,http://localhost:3005',
      },
      env_production: {
        NODE_ENV: 'production',
        API_PORT: 3020,
        PORT: 3020,
        API_URL: 'https://api.parentflowapp.com',
        CORS_ORIGIN: 'https://web.parentflowapp.com,https://api.parentflowapp.com,http://localhost:3030,http://localhost:3005',
        // Dedicated PostgreSQL Server
        DATABASE_HOST: '10.0.0.207',
        DATABASE_PORT: 5432,
        DATABASE_NAME: 'parentflow',
        DATABASE_USER: 'postgres',
        DATABASE_PASSWORD: 'a3ppq',
        DATABASE_SSL: 'false',
      },
      error_file: './logs/backend-error.log',
      out_file: './logs/backend-out.log',
      log_file: './logs/backend-combined.log',
      time: true,
      merge_logs: true,
      node_args: '--max-old-space-size=512',
      kill_timeout: 5000,
      wait_ready: true,
      listen_timeout: 10000
    },
    {
      name: 'parentflow-frontend-prod',
      cwd: './maternal-web',
      script: 'node_modules/next/dist/bin/next',
      args: 'start',
      instances: 1,
      exec_mode: 'cluster',
      autorestart: true,
      watch: false,
      max_memory_restart: '400M',
      env: {
        NODE_ENV: 'production',
        PORT: 3030,
        NEXT_PUBLIC_API_URL: 'https://api.parentflowapp.com',
      },
      env_production: {
        NODE_ENV: 'production',
        PORT: 3030,
        NEXT_PUBLIC_API_URL: 'https://api.parentflowapp.com',
        NEXT_PUBLIC_GRAPHQL_URL: 'https://api.parentflowapp.com/graphql',
        NEXT_PUBLIC_WS_URL: 'wss://api.parentflowapp.com/ws',
        NEXT_PUBLIC_APP_NAME: 'ParentFlow',
        NEXT_PUBLIC_APP_URL: 'https://web.parentflowapp.com',
      },
      error_file: './logs/frontend-error.log',
      out_file: './logs/frontend-out.log',
      log_file: './logs/frontend-combined.log',
      time: true,
      merge_logs: true,
      node_args: '--max-old-space-size=400',
      kill_timeout: 5000,
      wait_ready: true,
      listen_timeout: 30000
    },
    {
      name: 'parentflow-admin-prod',
      cwd: './parentflow-admin',
      script: 'node_modules/next/dist/bin/next',
      args: 'start',
      instances: 1,
      exec_mode: 'fork',
      autorestart: true,
      watch: false,
      max_memory_restart: '300M',
      env: {
        NODE_ENV: 'production',
        PORT: 3335,
        HOSTNAME: '0.0.0.0',
        NEXT_PUBLIC_API_URL: 'https://api.parentflowapp.com/api/v1',
        NEXT_PUBLIC_APP_URL: 'https://adminpf.parentflowapp.com',
        NEXT_PUBLIC_APP_NAME: 'ParentFlow Admin',
      },
      env_production: {
        NODE_ENV: 'production',
        PORT: 3335,
        HOSTNAME: '0.0.0.0',
        NEXT_PUBLIC_API_URL: 'https://api.parentflowapp.com/api/v1',
        NEXT_PUBLIC_APP_URL: 'https://adminpf.parentflowapp.com',
        NEXT_PUBLIC_APP_NAME: 'ParentFlow Admin',
      },
      error_file: './logs/admin-error.log',
      out_file: './logs/admin-out.log',
      log_file: './logs/admin-combined.log',
      time: true,
      merge_logs: true,
      node_args: '--max-old-space-size=300',
      kill_timeout: 5000,
      wait_ready: true,
      listen_timeout: 30000
    },
  ],
};
