version: '3.8'

services:
  crm_postgres:
    image: pgvector/pgvector:pg15
    container_name: crm_chatwoot_postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: crm_chatwoot_db
      POSTGRES_USER: crm_chatwoot_user
      POSTGRES_PASSWORD: crm_secure_password_2024
    volumes:
      - crm_postgres_data:/var/lib/postgresql/data
    ports:
      - "5435:5432"

  crm_redis:
    image: redis:7-alpine
    container_name: crm_chatwoot_redis
    restart: unless-stopped
    command: redis-server --appendonly yes
    volumes:
      - crm_redis_data:/data
    ports:
      - "6382:6379"

  crm_chatwoot:
    image: chatwoot/chatwoot:latest
    container_name: crm_chatwoot_app
    restart: unless-stopped
    depends_on:
      - crm_postgres
      - crm_redis
    environment:
      - NODE_ENV=production
      - RAISE_ON_UNPROCESSED_REQUEST=true
      - RAILS_ENV=production
      - SECRET_KEY_BASE=crm_genius_systems_online_secret_key_2024_unique
      - POSTGRES_HOST=crm_postgres
      - POSTGRES_DATABASE=crm_chatwoot_db
      - POSTGRES_USERNAME=crm_chatwoot_user
      - POSTGRES_PASSWORD=crm_secure_password_2024
      - REDIS_URL=redis://crm_redis:6379
      - FRONTEND_URL=https://crm.genius-systems.online
      - FORCE_SSL=false
      # FORCED Enterprise Configuration
      - INSTALLATION_PRICING_PLAN=enterprise
      - IS_ENTERPRISE=true
      - ENTERPRISE_EDITION=true
      - DISABLE_PREMIUM_ALERTS=true
      - HIDE_UPGRADE_NOTICE=true
      - MAX_AGENTS_PER_ACCOUNT=unlimited
      - MAX_INBOXES_PER_ACCOUNT=unlimited
      - MAX_TEAMS_PER_ACCOUNT=unlimited
      - ENABLE_ACCOUNT_SIGNUP=true
      - ENABLE_AUTOMATIONS=true
      - ENABLE_MACROS=true
      - ENABLE_SLA=true
      - ENABLE_CUSTOM_ROLES=true
      - ENABLE_AUDIT_LOGS=true
      - ENABLE_TEAM_MANAGEMENT=true
      - ENABLE_ADVANCED_REPORTS=true
      - ENABLE_WEBHOOKS=true
      # Additional enterprise enforcement
      - ENTERPRISE_LICENSE_KEY=EMERGENCY_RESTORE
      - DISABLE_LICENSE_CHECK=true
    ports:
      - "3003:3000"
    volumes:
      - crm_chatwoot_storage:/app/storage
    command: >
      sh -c "bundle exec rails db:chatwoot_prepare &&
             bundle exec rails s -p 3000 -b 0.0.0.0"

  crm_chatwoot_worker:
    image: chatwoot/chatwoot:latest
    container_name: crm_chatwoot_worker
    restart: unless-stopped
    depends_on:
      - crm_postgres
      - crm_redis
    environment:
      - NODE_ENV=production
      - RAILS_ENV=production
      - SECRET_KEY_BASE=crm_genius_systems_online_secret_key_2024_unique
      - POSTGRES_HOST=crm_postgres
      - POSTGRES_DATABASE=crm_chatwoot_db
      - POSTGRES_USERNAME=crm_chatwoot_user
      - POSTGRES_PASSWORD=crm_secure_password_2024
      - REDIS_URL=redis://crm_redis:6379
      - FRONTEND_URL=https://crm.genius-systems.online
      # FORCED Enterprise Configuration
      - INSTALLATION_PRICING_PLAN=enterprise
      - IS_ENTERPRISE=true
      - ENTERPRISE_EDITION=true
      - DISABLE_PREMIUM_ALERTS=true
      - HIDE_UPGRADE_NOTICE=true
      - MAX_AGENTS_PER_ACCOUNT=unlimited
      - MAX_INBOXES_PER_ACCOUNT=unlimited
      - MAX_TEAMS_PER_ACCOUNT=unlimited
      # Additional enterprise enforcement
      - ENTERPRISE_LICENSE_KEY=EMERGENCY_RESTORE
      - DISABLE_LICENSE_CHECK=true
    volumes:
      - crm_chatwoot_storage:/app/storage
    command: bundle exec sidekiq -C config/sidekiq.yml

volumes:
  crm_postgres_data:
  crm_redis_data:
  crm_chatwoot_storage:
