# /opt/docker/dev/service_finder/docker-compose.yml
services:
  # --- ADATBÁZIS KEZELÉS ---
  migrate:
    build: ./backend
    container_name: sentinel_migrate
    env_file: .env
    volumes:
      - ./backend:/app
    command: >
      bash -c "sleep 5 && alembic upgrade head && python -m app.final_admin_fix"
    networks:
      - sentinel_net
      - shared_db_net
    restart: "no"

  # --- KÖZPONTI API ---
  api:
    build: ./backend
    container_name: sentinel_api
    env_file: .env
    ports:
      - "8000:8000"
    volumes:
      - ./backend:/app
      - /mnt/nas/app_data:/mnt/nas/app_data
      - ./static_previews:/app/static/previews
    depends_on:
      migrate: { condition: service_completed_successfully }
      redis: { condition: service_started }
    networks:
      - sentinel_net
      - shared_db_net
    restart: unless-stopped

  # --- SZERVIZ HADOSZTÁLY (Service Robots) ---
  
  # Robot 1: Felfedező (OSM & Hunt)
  service_scout:
    build: ./backend
    container_name: sentinel_service_scout
    command: python -u -m app.workers.service.service_robot_1_scout_osm
    env_file: .env
    depends_on:
      api: { condition: service_started }
    networks:
      - sentinel_net
      - shared_db_net

  # Robot 2: Kutató (Adat pontosító - több példányban)
  service_researcher:
    build: ./backend
    container_name: sentinel_service_researcher
    command: python -u -m app.workers.service.service_robot_2_researcher
    deploy:
      replicas: 2
    env_file: .env
    networks:
      - sentinel_net
      - shared_db_net

  # Robot 3: Szakértő (AI dúsító - ExpertiseTags)
  service_enricher:
    build: ./backend
    container_name: sentinel_service_enricher
    command: python -u -m app.workers.service.service_robot_3_enricher
    env_file: .env
    networks:
      - sentinel_net
      - shared_db_net

  # --- JÁRMŰ HADOSZTÁLY (Vehicle Robots) ---

  # Robot 2: Alkimista (Technikai pontosítás - GPU igényes)
  vehicle_alchemist:
    build: ./backend
    container_name: sentinel_vehicle_alchemist
    command: python -u -m app.workers.vehicle.vehicle_robot_2_spec_fix
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    env_file: .env
    depends_on:
      ollama: { condition: service_started }
    networks:
      - sentinel_net
      - shared_db_net

  # --- RENDSZER HADOSZTÁLY (System Robots) ---

  # Robot 1: Dokumentum feldolgozó (OCR)
  system_ocr:
    build: ./backend
    container_name: sentinel_system_ocr
    command: python -u -m app.workers.system.robot_1_ocr_processor
    env_file: .env
    networks:
      - sentinel_net
    volumes:
      - /mnt/nas/app_data:/mnt/nas/app_data

  # --- AI MAG & INFRA ---
  ollama:
    image: ollama/ollama:latest
    container_name: sentinel_ollama
    volumes:
      - ./ollama_data:/root/.ollama
    ports:
      - "11434:11434"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    networks:
      - sentinel_net

  redis:
    image: redis:alpine
    container_name: sentinel_redis
    networks:
      - sentinel_net

  minio:
    image: minio/minio
    container_name: sentinel_minio
    env_file: .env
    command: server /data --console-address ":9001"
    volumes:
      - /mnt/nas/app_data/minio_data:/data
    networks:
      - sentinel_net

networks:
  sentinel_net:
    driver: bridge
  shared_db_net:
    external: true