# ============================================================================
# PROCP — Production compose (PRC-866). Batteries-included self-hosted.
# Kurulum:  cp .env.example .env  &&  docker compose -f docker-compose.prod.yml up -d --build
# Sonra:    tarayıcıda http://SUNUCU/install  (web installer sihirbazı)
# Tek imaj (procp:latest); roller command override ile.
# ============================================================================

x-app: &app-common
  # PRC-1128 — turnkey tek-satır kurulumda registry'den pull edilir
  # (get.procp.net → install-docker.sh → docker compose pull → Docker Hub).
  # Kaynaktan build için: docker compose -f docker-compose.prod.yml up -d --build.
  # Override: PROCP_IMAGE=kendi-registry/procp:tag
  image: ${PROCP_IMAGE:-bakcay/procp:latest}
  build:
    context: .
    dockerfile: docker/prod/Dockerfile
  env_file: [.env]
  restart: unless-stopped
  volumes:
    - procp-storage:/var/www/html/storage
  depends_on:
    mariadb:   { condition: service_healthy }
    redis:     { condition: service_started }
    meilisearch: { condition: service_started }
  networks: [procp]

services:
  # --- Web (php-fpm + nginx) ---
  app:
    <<: *app-common
    ports:
      - "${APP_PORT:-80}:80"
    # varsayılan CMD = supervisord (php-fpm+nginx)

  # --- Queue worker (provizyon + mail; olmazsa hizmet açılmaz/mail gitmez) ---
  worker:
    <<: *app-common
    command: ["php", "artisan", "queue:work", "redis", "--sleep=3", "--tries=3", "--max-time=3600", "--backoff=10"]
    ports: []

  # --- Scheduler (cron; billing/lifecycle/reminder/e-fatura) ---
  scheduler:
    <<: *app-common
    command: ["php", "artisan", "schedule:work"]
    ports: []

  # --- Reverb (WebSocket; canlı chat + realtime) ---
  reverb:
    <<: *app-common
    command: ["php", "artisan", "reverb:start", "--host=0.0.0.0", "--port=8080"]
    ports:
      - "${REVERB_PUBLIC_PORT:-8080}:8080"

  # --- MariaDB ---
  mariadb:
    image: mariadb:11
    restart: unless-stopped
    environment:
      MARIADB_DATABASE: "${DB_DATABASE:-procp}"
      MARIADB_USER: "${DB_USERNAME:-procp}"
      MARIADB_PASSWORD: "${DB_PASSWORD}"
      MARIADB_ROOT_PASSWORD: "${DB_PASSWORD}"
    volumes:
      - procp-db:/var/lib/mysql
    networks: [procp]
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 10

  # --- Redis ---
  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - procp-redis:/data
    networks: [procp]

  # --- Meilisearch ---
  meilisearch:
    image: getmeili/meilisearch:v1.16
    restart: unless-stopped
    environment:
      MEILI_MASTER_KEY: "${MEILISEARCH_KEY}"
      MEILI_ENV: production
    volumes:
      - procp-meili:/meili_data
    networks: [procp]

volumes:
  procp-storage:
  procp-db:
  procp-redis:
  procp-meili:

networks:
  procp:
    driver: bridge
