version: '3.8'

services:
  # ============================
  # BANCO DE DADOS PRINCIPAL
  # ============================
  postgres:
    image: postgres:15-alpine
    restart: always
    environment:
      POSTGRES_DB: edumanager
      POSTGRES_USER: edumanager
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-EduManager2026!Seguro}
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - edumanager-internal
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U edumanager"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ============================
  # STORAGE S3-COMPATIBLE (MINIO)
  # ============================
  minio:
    image: minio/minio:latest
    restart: always
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-MiniO2026!Seguro}
    volumes:
      - miniodata:/data
    networks:
      - edumanager-internal
      - network_public
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.edum-minio.rule=Host(`storageedu.microtecinformaticacurso.com.br`)"
        - "traefik.http.routers.edum-minio.entrypoints=websecure"
        - "traefik.http.routers.edum-minio.tls=true"
        - "traefik.http.routers.edum-minio.tls.certresolver=letsencrypt"
        - "traefik.http.services.edum-minio.loadbalancer.server.port=9000"
        - "traefik.docker.network=network_public"

  # ============================
  # EDUMANAGER (PAINEL ADMIN)
  # ============================
  edumanager:
    image: ghcr.io/sidney201900/edumanager-pro2026/edumanager:latest
    restart: always
    depends_on:
      - postgres
      - minio
    environment:
      - NODE_ENV=production
      - PORT=3000
      - DATABASE_URL=postgresql://edumanager:${POSTGRES_PASSWORD:-EduManager2026!Seguro}@postgres:5432/edumanager
      - JWT_SECRET=${JWT_SECRET:-EduManager-JWT-Secret-2026!}
      - MINIO_ENDPOINT=minio
      - MINIO_PORT=9000
      - MINIO_ACCESS_KEY=${MINIO_ROOT_USER:-minioadmin}
      - MINIO_SECRET_KEY=${MINIO_ROOT_PASSWORD:-MiniO2026!Seguro}
      - MINIO_PUBLIC_URL=${MINIO_PUBLIC_URL:-https://storageedu.microtecinformaticacurso.com.br}
      - ASAAS_API_KEY=${ASAAS_API_KEY}
      - ASAAS_API_URL=${ASAAS_API_URL}
      - ASAAS_WEBHOOK_TOKEN=${ASAAS_WEBHOOK_TOKEN}
    networks:
      - edumanager-internal
      - network_public
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.edum-manager.rule=Host(`edumanager.microtecinformaticacurso.com.br`)"
        - "traefik.http.routers.edum-manager.entrypoints=websecure"
        - "traefik.http.routers.edum-manager.tls=true"
        - "traefik.http.routers.edum-manager.tls.certresolver=letsencrypt"
        - "traefik.http.services.edum-manager.loadbalancer.server.port=3000"
        - "traefik.docker.network=network_public"

  # ============================
  # PORTAL DO ALUNO
  # ============================
  portalaluno:
    image: ghcr.io/sidney201900/edumanager-pro2026/portalaluno:latest
    restart: always
    depends_on:
      - postgres
    environment:
      - NODE_ENV=production
      - PORT=3001
      - DATABASE_URL=postgresql://edumanager:${POSTGRES_PASSWORD:-EduManager2026!Seguro}@postgres:5432/edumanager
      - JWT_SECRET=${JWT_SECRET:-EduManager-JWT-Secret-2026!}
      - MINIO_ENDPOINT=minio
      - MINIO_PORT=9000
      - MINIO_ACCESS_KEY=${MINIO_ROOT_USER:-minioadmin}
      - MINIO_SECRET_KEY=${MINIO_ROOT_PASSWORD:-MiniO2026!Seguro}
      - MINIO_PUBLIC_URL=${MINIO_PUBLIC_URL:-https://storageedu.microtecinformaticacurso.com.br}
    networks:
      - edumanager-internal
      - network_public
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.edum-portal.rule=Host(`aluno.microtecinformaticacurso.com.br`)"
        - "traefik.http.routers.edum-portal.entrypoints=websecure"
        - "traefik.http.routers.edum-portal.tls=true"
        - "traefik.http.routers.edum-portal.tls.certresolver=letsencrypt"
        - "traefik.http.services.edum-portal.loadbalancer.server.port=3001"
        - "traefik.docker.network=network_public"

volumes:
  pgdata:
  miniodata:

networks:
  edumanager-internal:
    driver: overlay
  network_public:
    external: true
