# BuyerKiosk Development Docker Compose
# Usage:
#   docker-compose up -d              # Start all services
#   docker-compose logs -f web        # Tail web logs
#   docker-compose exec web bash      # Shell into web container
#   docker-compose down               # Stop and remove containers

services:
  # Main PHP/Apache Application
  web:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: buyerkiosk-web
    ports:
      - "8080:80"
    volumes:
      - ./public_html:/var/www/html/public_html
      - ./userfrosting:/var/www/html/userfrosting
      - ./logs:/var/www/html/logs
      - ./test.sh:/var/www/html/test.sh:ro
      - composer_cache:/root/.composer
    environment:
      - DB_HOST=mysql
      - DB_USER=kiosk_db
      - DB_PASS=kiosk_dev_password
      - DB_NAME=kiosk_buykiosk
      - DB_PREFIX=resaleki_
      - BUYDB_NAME=kiosk_buys
      - USERSDB_NAME=kiosk_users
      - CONTACTDB_NAME=contactNumbers
      - REDIS_URL=tcp://redis:6379
      - DEV=1
      - APP_ENV=development
      - SERVER_NAME=localhost
      - APP_DOMAIN=http://localhost:8080
      - XDEBUG_MODE=develop,debug
      - XDEBUG_CONFIG=client_host=host.docker.internal
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started
    networks:
      - buyerkiosk-network
    extra_hosts:
      - "host.docker.internal:host-gateway"

  # MySQL Database
  mysql:
    image: mysql:8.0
    container_name: buyerkiosk-mysql
    ports:
      - "3307:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root_password
      - MYSQL_USER=kiosk_db
      - MYSQL_PASSWORD=kiosk_dev_password
    volumes:
      - mysql_data:/var/lib/mysql
      - ./docker/mysql/init:/docker-entrypoint-initdb.d:ro
      - ./docker/mysql/conf.d:/etc/mysql/conf.d:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot_password"]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - buyerkiosk-network

  # Redis Cache & Queue
  redis:
    image: redis:7-alpine
    container_name: buyerkiosk-redis
    ports:
      - "6380:6379"
    volumes:
      - redis_data:/data
    command: redis-server --appendonly yes
    networks:
      - buyerkiosk-network

  # TaskEngine Background Worker
  worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: buyerkiosk-worker
    volumes:
      - ./public_html:/var/www/html/public_html
      - ./userfrosting:/var/www/html/userfrosting
      - ./logs:/var/www/html/logs
    environment:
      - DB_HOST=mysql
      - DB_USER=kiosk_db
      - DB_PASS=kiosk_dev_password
      - DB_NAME=kiosk_buykiosk
      - DB_PREFIX=resaleki_
      - BUYDB_NAME=kiosk_buys
      - USERSDB_NAME=kiosk_users
      - CONTACTDB_NAME=contactNumbers
      - REDIS_URL=tcp://redis:6379
      - DEV=1
      - APP_ENV=development
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started
    command: ["php", "/var/www/html/userfrosting/bin/task", "worker:start", "--queues=high,default,low"]
    restart: unless-stopped
    networks:
      - buyerkiosk-network

  # Mailhog for local email testing (optional)
  mailhog:
    image: mailhog/mailhog:latest
    container_name: buyerkiosk-mailhog
    ports:
      - "1025:1025"  # SMTP
      - "8025:8025"  # Web UI
    networks:
      - buyerkiosk-network

  # Adminer for database management (optional)
  adminer:
    image: adminer:latest
    container_name: buyerkiosk-adminer
    ports:
      - "8081:8080"
    environment:
      - ADMINER_DEFAULT_SERVER=mysql
    depends_on:
      - mysql
    networks:
      - buyerkiosk-network

networks:
  buyerkiosk-network:
    driver: bridge

volumes:
  mysql_data:
    driver: local
  redis_data:
    driver: local
  composer_cache:
    driver: local
