services:
  # ── Backend: API Principal (Express + BullMQ) ───────────────────────────
  backend:
    build:
      context: ./backend
      dockerfile: ../infra/backend.Dockerfile
    container_name: mercado-backend-prod
    restart: unless-stopped
    env_file: .env
    environment:
      - PORT=4001
      - REDIS_HOST=mercado-redis
      - NODE_ENV=production
    volumes:
      - ./backend:/app
      - /app/node_modules
    networks:
      - web
      - internal
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.mercado-api.rule=Host(`mercado.clube67.com`) && PathPrefix(`/api`)"
      - "traefik.http.routers.mercado-api.entrypoints=websecure"
      - "traefik.http.routers.mercado-api.tls.certresolver=letsencrypt"
      - "traefik.http.services.mercado-api.loadbalancer.server.port=4001"

  # ── Redis: Para Filas e Cache ───────────────────────────────────────────
  redis:
    image: redis:alpine
    container_name: mercado-redis
    restart: unless-stopped
    networks:
      - internal

  # ── Frontend: App Cliente (Vite/React) ──────────────────────────────────
  frontend-customer:
    image: nginx:alpine
    container_name: mercado-customer-prod
    restart: unless-stopped
    volumes:
      - ./frontend/customer/dist:/usr/share/nginx/html
      - ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - web
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.mercado-customer.rule=Host(`mercado.clube67.com`)"
      - "traefik.http.routers.mercado-customer.entrypoints=websecure"
      - "traefik.http.routers.mercado-customer.tls.certresolver=letsencrypt"
      - "traefik.http.services.mercado-customer.loadbalancer.server.port=80"

  # ── Frontend: Admin (Gestão Tenancy) ────────────────────────────────────
  frontend-admin:
    image: nginx:alpine
    container_name: mercado-admin-prod
    restart: unless-stopped
    volumes:
      - ./frontend/admin/dist:/usr/share/nginx/html
      - ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - web
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.mercado-admin.rule=Host(`admin-mercado.clube67.com`)"
      - "traefik.http.routers.mercado-admin.entrypoints=websecure"
      - "traefik.http.routers.mercado-admin.tls.certresolver=letsencrypt"
      - "traefik.http.services.mercado-admin.loadbalancer.server.port=80"

  # ── Frontend: SuperAdmin ────────────────────────────────────────────────
  frontend-superadmin:
    image: nginx:alpine
    container_name: mercado-superadmin-prod
    restart: unless-stopped
    volumes:
      - ./frontend/superadmin/dist:/usr/share/nginx/html
      - ./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - web
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.mercado-superadmin.rule=Host(`superadmin-mercado.clube67.com`)"
      - "traefik.http.routers.mercado-superadmin.entrypoints=websecure"
      - "traefik.http.routers.mercado-superadmin.tls.certresolver=letsencrypt"
      - "traefik.http.services.mercado-superadmin.loadbalancer.server.port=80"

networks:
  web:
    external: true
  internal:
    driver: bridge
