version: "3.9"

services:
  # ---- PostgreSQL ----
  postgres:
    image: postgres:16-alpine
    container_name: safety-pro-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: safetyuser
      POSTGRES_PASSWORD: safetypass
      POSTGRES_DB: safetydb
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U safetyuser -d safetydb"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ---- Redis ----
  redis:
    image: redis:7-alpine
    container_name: safety-pro-redis
    restart: unless-stopped
    command: redis-server --appendonly yes
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ---- MinIO (S3 compatible — dev uniquement) ----
  minio:
    image: minio/minio:latest
    container_name: safety-pro-minio
    restart: unless-stopped
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - minio_data:/data
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ---- MailHog (SMTP dev — UI emails) ----
  mailhog:
    image: mailhog/mailhog:latest
    container_name: safety-pro-mailhog
    restart: unless-stopped
    ports:
      - "1025:1025"
      - "8025:8025"

  # ---- MinIO bucket init ----
  minio-init:
    image: minio/mc:latest
    container_name: safety-pro-minio-init
    depends_on:
      minio:
        condition: service_healthy
    entrypoint: >
      /bin/sh -c "
        mc alias set local http://minio:9000 minioadmin minioadmin &&
        mc mb --ignore-existing local/safety-pro &&
        mc anonymous set download local/safety-pro/public
      "
    restart: "no"

volumes:
  postgres_data:
  redis_data:
  minio_data:
