# /opt/docker/dev/service_finder/docker-compose.yml
services:

  # --- ADATBÁZIS MIGRÁCIÓ (Opcionális segéd) ---
  migrate:
    build: ./backend
    container_name: sf_migrate
    env_file: .env
    volumes:
      - ./backend:/app
      - /opt/docker/scripts:/opt/docker/scripts
    command: >
      bash -c "sleep 2 && alembic upgrade head && PYTHONPATH=/app python -m app.tests_internal.fixes.final_admin_fix"
    networks:
      - sf_net
      - shared_db_net
    # Nem függünk a helyi postgres-től, mert az external
    restart: "no"

  # --- KÖZPONTI API ---
  sf_api:
    build: ./backend
    container_name: sf_api
    env_file: .env
    environment:
      - ALLOWED_ORIGINS=https://app.servicefinder.hu,https://admin.servicefinder.hu,https://dev.servicefinder.hu,http://192.168.100.10:8503,http://localhost:5173,http://localhost:3001
    ports:
      - "8000:8000"
    volumes:
      - ./backend:/app
      - /mnt/nas/app_data:/mnt/nas/app_data
      - ./static_previews:/app/static/previews
    command: ["/bin/bash", "/app/app/scripts/pre_start.sh"]
    # Figyelem: A migráció nem blokkolja tovább az indulást!
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

  # --- SZERVIZ HADOSZTÁLY ---
  sf_service_scout:
    build: ./backend
    container_name: sf_service_scout
    command: python -u -m app.workers.service.service_robot_1_scout_osm
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_service_hunter:
    build: ./backend
    container_name: sf_service_hunter
    command: python -u -m app.workers.service.service_robot_0_hunter
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_service_researcher:
    build: ./backend
    command: python -u -m app.workers.service.service_robot_2_researcher
    deploy:
      replicas: 2
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_service_enricher:
    build: ./backend
    container_name: sf_service_enricher
    command: python -u -m app.workers.service.service_robot_3_enricher
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_service_validator:
    build: ./backend
    container_name: sf_service_validator
    command: python -u -m app.workers.service.service_robot_4_validator_google
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  # --- JÁRMŰ HADOSZTÁLY ---
  sf_vehicle_discovery:
    build: ./backend
    container_name: sf_vehicle_discovery
    command: python -u -m app.workers.vehicle.vehicle_robot_0_discovery_engine
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_vehicle_hunter:
    build: ./backend
    container_name: sf_vehicle_hunter
    command: python -u -m app.workers.vehicle.vehicle_robot_1_catalog_hunter
    env_file: .env
    volumes:                  # <-- EZT ADD HOZZÁ
      - ./backend:/app
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_nhtsa_hunter:
    build: ./backend
    container_name: sf_nhtsa_hunter
    command: python -m app.workers.vehicle.vehicle_robot_1_2_nhtsa_fetcher
    env_file: .env
    restart: unless-stopped
    networks:
      - sf_net
      - shared_db_net

  sf_bike_hunter:
    build: ./backend
    container_name: sf_bike_hunter
    command: python -m app.workers.vehicle.vehicle_robot_1_4_bike_hunter
    env_file: .env
    restart: unless-stopped
    networks:
      - sf_net
      - shared_db_net

  sf_vehicle_researcher:
    build: ./backend
    command: python -u -m app.workers.vehicle.vehicle_robot_2_researcher
    deploy:
      replicas: 2
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_heavy_eu:
    build: ./backend
    container_name: sf_heavy_eu
    command: python -m app.workers.vehicle.vehicle_robot_1_5_heavy_eu
    env_file: .env
    restart: unless-stopped
    entrypoint: >
      /bin/sh -c "python -m app.worker.heavy_eu && echo 'Vége, pihenő...' && sleep 36000"
    networks:
      - sf_net
      - shared_db_net

  sf_rdw_enricher:
    build: ./backend
    container_name: sf_rdw_enricher
    command: python -m app.workers.vehicle.vehicle_robot_2_1_rdw_enricher
    env_file: .env
    volumes:
      - ./backend:/app  # <-- EZ KELL, HOGY LÁSSA A MAPPING FÁJLOKAT!
    networks:
      sf_net:
      shared_db_net:
        aliases:
          - rdw_worker # Belső azonosító
    restart: always

  sf_vehicle_alchemist:
    build: ./backend
    container_name: sf_vehicle_alchemist
    command: python -u -m app.workers.vehicle.vehicle_robot_3_alchemist_pro
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_vehicle_vin_auditor:
    build: ./backend
    container_name: sf_vehicle_vin_auditor
    command: python -u -m app.workers.vehicle.vehicle_robot_4_vin_auditor
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_vehicle_validator:
    build: ./backend
    container_name: sf_vehicle_validator
    command: python -u -m app.workers.vehicle.vehicle_robot_4_validator
    env_file: .env
    volumes:
      - ./backend:/app
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  # --- GB (ANGOL) JÁRMŰ HADOSZTÁLY ---
  sf_gb_vehicle_discovery:
    build: ./backend
    container_name: sf_gb_vehicle_discovery
    command: python -u -m app.workers.vehicle.vehicle_robot_0_gb_discovery
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_gb_vehicle_hunter:
    build: ./backend
    container_name: sf_gb_vehicle_hunter
    command: python -u -m app.workers.vehicle.vehicle_robot_1_gb_hunter
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  # --- RENDSZER HADOSZTÁLY ---
  sf_system_ocr:
    build: ./backend
    container_name: sf_system_ocr
    command: python -u -m app.workers.ocr.robot_1_ocr_processor
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    volumes:
      - ./backend:/app
      - /mnt/nas/app_data:/mnt/nas/app_data
    restart: unless-stopped

  sf_system_auditor:
    build: ./backend
    container_name: sf_system_auditor
    command: python -u -m app.workers.service.service_robot_5_auditor
    env_file: .env
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  # --- ADMIN WEBES FELÜLET (HITL) ---
  sf_admin_ui:
    build: ./backend
    container_name: sf_admin_ui
    command: streamlit run app/admin_ui.py --server.port=8501 --server.address=0.0.0.0
    env_file: .env
    ports:
      - "8501:8501"
    volumes:
      - ./backend:/app
      - /mnt/nas/app_data:/mnt/nas/app_data
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  # --- NUXT 3 ADMIN FRONTEND (Epic 10 - Mission Control) ---
  sf_admin_frontend:
    build:
      context: ./frontend/admin
      dockerfile: Dockerfile.dev
    container_name: sf_admin_frontend
    env_file: .env
    ports:
      - "8502:8502"
    environment:
      - NUXT_PORT=8502
      - NUXT_HOST=0.0.0.0
      - NUXT_PUBLIC_API_BASE_URL=https://dev.servicefinder.hu
    volumes:
      - ./frontend/admin:/app
      - /app/node_modules
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  # --- PUBLIC FRONTEND (Epic 11 - Public Portal) ---
  sf_public_frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile.dev
    container_name: sf_public_frontend
    command: npm run dev -- --host 0.0.0.0
    env_file: .env
    ports:
      - "8503:5173"
    environment:
      - VITE_API_BASE_URL=http://sf_api:8000
    volumes:
      - ./frontend:/app
      - /app/node_modules
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  # --- ULTIMATESPECS ROBOTOK (A Turbó fokozat) ---
  sf_ultimate_r0_spider:
    build: ./backend
    container_name: sf_ultimate_r0_spider
    command: bash -c "playwright install chromium && playwright install-deps && python -u -m app.workers.vehicle.ultimatespecs.vehicle_ultimate_r0_spider"
    env_file: .env
    volumes:
      - ./backend:/app
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_ultimate_r1_scraper:
    build: ./backend
    container_name: sf_ultimate_r1_scraper
    command: bash -c "playwright install chromium && playwright install-deps && python -u -m app.workers.vehicle.ultimatespecs.vehicle_ultimate_r1_scraper"
    env_file: .env
    volumes:
      - ./backend:/app
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_ultimate_r2_enricher:
    build: ./backend
    container_name: sf_ultimate_r2_enricher
    command: python -u -m app.workers.vehicle.ultimatespecs.vehicle_ultimate_r2_enricher
    env_file: .env
    volumes:
      - ./backend:/app
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  sf_ultimate_r3_finalizer:
    build: ./backend
    container_name: sf_ultimate_r3_finalizer
    command: python -u -m app.workers.vehicle.ultimatespecs.vehicle_ultimate_r3_finalizer
    env_file: .env
    volumes:
      - ./backend:/app
    networks:
      - sf_net
      - shared_db_net
    restart: unless-stopped

  # --- PERMANENT TEST LAB & CI/CD PIPELINE ---
  sf_tester:
    image: mcr.microsoft.com/playwright:v1.58.2-jammy
    container_name: sf_tester
    volumes:
      - ./frontend:/app
      - sf_tester_node_modules:/app/node_modules
    networks:
      - sf_net
      - shared_db_net
    command: tail -f /dev/null
    restart: unless-stopped

  # --- MAILPIT (E-MAIL TESZTELÉS) ---
  sf_mailpit:
    image: axllent/mailpit
    container_name: sf_mailpit
    ports:
      - "8025:8025"   # Web UI
      - "1025:1025"   # SMTP port
    networks:
      - sf_net
    restart: unless-stopped

volumes:
  sf_tester_node_modules:

networks:
  sf_net:
    driver: bridge
  shared_db_net:
    external: true
