services:
  redis:
    image: redis:7
    container_name: redis
    ports:
      - "6301:6379"
    networks:
      - app-network
    command: redis-server --port 6379
    healthcheck:
      test: ["CMD", "redis-cli", "-p", "6379", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3

  backend:
    build: .
    container_name: backend
    ports:
      - "9000:9000"
    environment:
      - NODE_OPTIONS=--max-old-space-size=4096
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - CORS_ORIGINS=https://api.vzzpr.thesuitchstaging2.com:9000
      - APP_URL=https://api.vzzpr.thesuitchstaging2.com:9000/api/v1
    env_file:
      - .env
    depends_on:
      redis:
        condition: service_healthy
    networks:
      - app-network
    healthcheck:
      test: ["CMD", "curl", "-f", "https://api.vzzpr.thesuitchstaging2.com:9000/api/v1/video/health"]
      interval: 30s
      timeout: 10s
      retries: 3

  notification-worker:
    build:
      context: .
      dockerfile: Dockerfile.worker
    container_name: notification-worker
    environment:
      - NODE_OPTIONS=--max-old-space-size=1024
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - NOTIF_WORKER_CONCURRENCY=2
      - WORKER_HEALTH_PORT=8092
      - TS_NODE_TRANSPILE_ONLY=1
      - NODE_ENV=development
    env_file:
      - .env
    depends_on:
      redis:
        condition: service_healthy
      backend:
        condition: service_healthy
    networks:
      - app-network
    command: ["npm", "run", "worker:notification"]
    restart: unless-stopped
    ports:
      - "8092:8092"

  video-worker:
    build:
      context: .
      dockerfile: Dockerfile.worker
    container_name: video-worker
    environment:
      - NODE_OPTIONS=--max-old-space-size=4096
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - VIDEO_WORKER_CONCURRENCY=2
      - WORKER_HEALTH_PORT=9001
      - TS_NODE_TRANSPILE_ONLY=1
      - NODE_ENV=development
    env_file:
      - .env
    depends_on:
      redis:
        condition: service_healthy
      backend:
        condition: service_healthy
    networks:
      - app-network
    command: ["npm", "run", "worker:video"]
    restart: unless-stopped
    volumes:
      - video-processing-temp:/tmp/video-processing
    ports:
      - "9001:9001"

volumes:
  video-processing-temp:

networks:
  app-network:
    driver: bridge
