services:
  # PostgreSQL Database
  postgres:
    image: postgres:16-alpine
    container_name: elearning-postgres
    restart: unless-stopped
    security_opt:
      - apparmor=unconfined
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: elearning_dev
      POSTGRES_PASSWORD: 12345678
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - elearning-network
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U elearning" ]
      interval: 10s
      timeout: 5s
      retries: 5

  # MinIO - S3 Compatible Storage
  minio:
    image: minio/minio:latest
    deploy:
      resources:
        limits:
          memory: 1G
    container_name: elearning-minio
    restart: unless-stopped
    security_opt:
      - apparmor=unconfined
    ports:
      - "9000:9000" # API
      - "9001:9001" # Console
    environment:
      - TZ=Asia/Bangkok
      - MINIO_ROOT_USER=admin
      - MINIO_ROOT_PASSWORD=12345678
    volumes:
      - minio_data:/data
    command: server /data --console-address ":9001"
    networks:
      - elearning-network
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:9000/minio/health/live" ]
      interval: 30s
      timeout: 20s
      retries: 3

  # Mailhog - Email Testing
  mailhog:
    image: mailhog/mailhog:latest
    container_name: elearning-mailhog
    restart: unless-stopped
    security_opt:
      - apparmor=unconfined
    ports:
      - "1025:1025" # SMTP
      - "8025:8025" # Web UI
    networks:
      - elearning-network

  # Adminer - Database Management UI
  adminer:
    image: adminer:latest
    container_name: elearning-adminer
    restart: unless-stopped
    security_opt:
      - apparmor=unconfined
    ports:
      - "8080:8080"
    environment:
      ADMINER_DEFAULT_SERVER: postgres
      ADMINER_DESIGN: dracula
    networks:
      - elearning-network
    depends_on:
      - postgres

volumes:
  postgres_data:
    driver: local
  minio_data:
    driver: local

networks:
  elearning-network:
    driver: bridge
