services:
  # === GPU-Modus (Produktion auf Unraid) ===
  # Starten mit: docker compose --profile gpu up --build
  # Unraid: nobody:users = 99:100
  video-konverter:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: video-konverter
    restart: unless-stopped
    user: "${PUID:-99}:${PGID:-100}"
    ports:
      - "${VK_PORT:-8080}:8080"
    volumes:
      # Konfiguration (persistent)
      - ./video-konverter/app/cfg:/opt/video-konverter/app/cfg
      # Daten (Queue-Persistierung)
      - ./data:/opt/video-konverter/data
      # Logs
      - ./logs:/opt/video-konverter/logs
      # /mnt 1:1 durchreichen - Pfade von Dolphin stimmen dann im Container
      - /mnt:/mnt:rw
    devices:
      # Alle GPUs durchreichen - VK_GPU_DEVICE waehlt die richtige
      - /dev/dri:/dev/dri
    group_add:
      - "video"
    environment:
      # GPU-Treiber
      - LIBVA_DRIVER_NAME=iHD
      - LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri
      # === VideoKonverter Konfiguration (VK_*) ===
      # Alle Werte ueberschreiben die settings.yaml
      # Datenbank
      - VK_DB_HOST=${VK_DB_HOST:-192.168.155.11}
      - VK_DB_PORT=${VK_DB_PORT:-3306}
      - VK_DB_USER=${VK_DB_USER:-video}
      - VK_DB_PASSWORD=${VK_DB_PASSWORD:-8715}
      - VK_DB_NAME=${VK_DB_NAME:-video_converter}
      # Encoding
      - VK_MODE=gpu
      - VK_GPU_DEVICE=${VK_GPU_DEVICE:-/dev/dri/renderD129}
      - VK_MAX_JOBS=${VK_MAX_JOBS:-1}
      - VK_DEFAULT_PRESET=${VK_DEFAULT_PRESET:-gpu_av1_10bit}
      # Library / TVDB
      - VK_TVDB_API_KEY=${VK_TVDB_API_KEY:-}
      - VK_TVDB_LANGUAGE=${VK_TVDB_LANGUAGE:-deu}
      # Logging
      - VK_LOG_LEVEL=${VK_LOG_LEVEL:-INFO}
    profiles:
      - gpu

  # === CPU-Modus (lokales Testen ohne GPU) ===
  # Starten mit: docker compose --profile cpu up --build
  # Lokal: CIFS-Mount nutzt UID 1000, daher PUID/PGID ueberschreiben:
  #   PUID=1000 PGID=1000 docker compose --profile cpu up --build
  video-konverter-cpu:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: video-konverter-cpu
    user: "${PUID:-99}:${PGID:-100}"
    ports:
      - "${VK_PORT:-8080}:8080"
    volumes:
      - ./video-konverter/app/cfg:/opt/video-konverter/app/cfg
      - ./data:/opt/video-konverter/data
      - ./logs:/opt/video-konverter/logs
      # /mnt 1:1 durchreichen - Pfade identisch zum Host
      - /mnt:/mnt:rw
    environment:
      # === VideoKonverter Konfiguration (VK_*) ===
      # Datenbank
      - VK_DB_HOST=${VK_DB_HOST:-192.168.155.11}
      - VK_DB_PORT=${VK_DB_PORT:-3306}
      - VK_DB_USER=${VK_DB_USER:-video}
      - VK_DB_PASSWORD=${VK_DB_PASSWORD:-8715}
      - VK_DB_NAME=${VK_DB_NAME:-video_converter}
      # Encoding
      - VK_MODE=cpu
      - VK_MAX_JOBS=${VK_MAX_JOBS:-1}
      - VK_DEFAULT_PRESET=${VK_DEFAULT_PRESET:-cpu_av1}
      # Library / TVDB
      - VK_TVDB_API_KEY=${VK_TVDB_API_KEY:-}
      - VK_TVDB_LANGUAGE=${VK_TVDB_LANGUAGE:-deu}
      # Logging
      - VK_LOG_LEVEL=${VK_LOG_LEVEL:-INFO}
    profiles:
      - cpu
