version: '3.8'

services:
  app:
    build: .
    container_name: qwen-hack-moh
    ports:
      - "18000:18000"
    environment:
      - APP_ENV=development
      - DB_HOST=database
      - DB_NAME=moh
      - DB_USER=moh_user
      - DB_PASS=moh_password
      - JWT_SECRET=MerchantsOfHopeSecretKeyChangeInProduction
    volumes:
      - .:/var/www/html
      - ./docker/logs:/var/log/app
    depends_on:
      - database
      - redis
      - mailhog
    networks:
      - moh-network

  database:
    image: postgres:13
    container_name: moh-database
    environment:
      - POSTGRES_DB=moh
      - POSTGRES_USER=moh_user
      - POSTGRES_PASSWORD=moh_password
    ports:
      - "5432:5432"
    volumes:
      - moh_db_data:/var/lib/postgresql/data
      - ./docker/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - moh-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U moh_user -d moh"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:alpine
    container_name: moh-redis
    ports:
      - "6379:6379"
    volumes:
      - moh_redis_data:/data
    networks:
      - moh-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  mailhog:
    image: mailhog/mailhog
    container_name: moh-mailhog
    ports:
      - "1025:1025"  # SMTP
      - "8025:8025"  # Web UI
    networks:
      - moh-network

  nginx:
    image: nginx:alpine
    container_name: moh-nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - .:/var/www/html
      - ./docker/nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - app
    networks:
      - moh-network
    restart: unless-stopped

volumes:
  moh_db_data:
  moh_redis_data:

networks:
  moh-network:
    driver: bridge