services:
  # ===========================================
  # Laravel Application
  # ===========================================
  laravel:
    build:
      context: .
      dockerfile: Dockerfile
    working_dir: /var/www
    entrypoint: ["/var/www/docker/entrypoint.sh"]
    command: ["php", "artisan", "serve", "--host=0.0.0.0", "--port=8000"]
    volumes:
      - ./:/var/www
      - ./docker/docker.env:/var/www/.env
      - vendor_data:/var/www/vendor
      - node_modules_data:/var/www/node_modules
    ports:
      - "8000:8000"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000"]
      interval: 10s
      timeout: 5s
      retries: 30
      start_period: 300s
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - moro

  # ===========================================
  # Queue Worker (for background jobs)
  # ===========================================
  queue:
    build:
      context: .
      dockerfile: Dockerfile
    working_dir: /var/www
    entrypoint: []
    command: php artisan queue:work redis --queue=high,moro,default --sleep=3 --tries=3 --max-time=3600
    volumes:
      - ./:/var/www
      - ./docker/docker.env:/var/www/.env
      - vendor_data:/var/www/vendor
      - node_modules_data:/var/www/node_modules
    depends_on:
      laravel:
        condition: service_healthy
    restart: unless-stopped
    networks:
      - moro

  # ===========================================
  # Task Scheduler (cron)
  # ===========================================
  scheduler:
    build:
      context: .
      dockerfile: Dockerfile
    working_dir: /var/www
    entrypoint: []
    command: >
      bash -c "while true; do php artisan schedule:run --verbose --no-interaction; sleep 60; done"
    volumes:
      - ./:/var/www
      - ./docker/docker.env:/var/www/.env
      - vendor_data:/var/www/vendor
      - node_modules_data:/var/www/node_modules
    depends_on:
      laravel:
        condition: service_healthy
    restart: unless-stopped
    networks:
      - moro

  # ===========================================
  # MySQL Database
  # ===========================================
  mysql:
    image: mysql:8.0
    ports:
      - "33061:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./docker/moro.sql:/docker-entrypoint-initdb.d/001-import.sql
    environment:
      MYSQL_DATABASE: moro
      MYSQL_USER: moro
      MYSQL_PASSWORD: abc1234$$
      MYSQL_ROOT_PASSWORD: abc1234$$
    command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max-allowed-packet=256M
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-pabc1234$$"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 120s
    networks:
      - moro

  # ===========================================
  # Redis (cache, session, queue)
  # ===========================================
  redis:
    image: redis:7-alpine
    ports:
      - "63790:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3
    networks:
      - moro

  # ===========================================
  # phpMyAdmin (optional - database management)
  # ===========================================
  phpmyadmin:
    image: phpmyadmin:5
    ports:
      - "8080:80"
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
      MYSQL_ROOT_PASSWORD: abc1234$$
      UPLOAD_LIMIT: 100M
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - moro
    profiles:
      - tools

  # ===========================================
  # Mailpit (optional - email testing)
  # ===========================================
  mailpit:
    image: axllent/mailpit:latest
    ports:
      - "8025:8025"
      - "1025:1025"
    networks:
      - moro
    profiles:
      - tools

volumes:
  mysql_data:
  redis_data:
  vendor_data:
  node_modules_data:

networks:
  moro:
    driver: bridge
