services:
  # 1. ADATBÁZIS (NAS-ra mentett adatokkal)
  postgres-db:
    image: postgres:15
    container_name: postgres-db
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      # A perzisztens adatbázis fájlok a NAS-ra kerülnek
      - /mnt/nas/app_data/postgres_data:/var/lib/postgresql/data
    ports:
      - "${POSTGRES_PORT}:${POSTGRES_PORT}"
    networks:
      - service_finder_net
    restart: unless-stopped

  # 2. BACKEND API (NAS-on lévő kódbázissal)
  service_finder_api:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: service_finder_api
    volumes:
      # A forráskódot a NAS-ról olvassa be
      - /mnt/nas/git_vault/service_finder/backend:/app
    command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --proxy-headers --forwarded-allow-ips="*"
    ports:
      - "8000:8000"
    environment:
      - PYTHONPATH=/app
      - DATABASE_URL=postgresql+asyncpg://${APP_DB_USER}:${APP_DB_PASSWORD}@postgres-db:${APP_DB_PORT}/${APP_DB_NAME}
      - SECRET_KEY=${SECRET_KEY}
      - ALLOWED_ORIGINS=https://dev.profibot.hu,https://app.profibot.hu
      - MINIO_ENDPOINT=minio:9000
      - MINIO_ACCESS_KEY=${POSTGRES_USER}
      - MINIO_SECRET_KEY=${POSTGRES_PASSWORD}
    depends_on:
      - postgres-db
      - minio
      - redis
    networks:
      - service_finder_net

  # 3. PGADMIN (Adminisztrációs felület)
  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin_ui
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
    volumes:
      # A pgAdmin beállításai is maradjanak meg a NAS-on
      - /mnt/nas/app_data/pgadmin_data:/var/lib/pgadmin
    ports:
      - "5050:80"
    depends_on:
      - postgres-db
    networks:
      - service_finder_net

  # 4. MINIO (A fájlok fizikai helye a NAS)
  minio:
    image: minio/minio
    container_name: service_finder_minio
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: ${POSTGRES_USER}
      MINIO_ROOT_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      # Ez a legfontosabb: a képek és számlák a NAS-ra mennek
      - /mnt/nas/app_data/minio_data:/data
    ports:
      - "9000:9000"
      - "9001:9001"
    networks:
      - service_finder_net

  # 5. REDIS (Gyorsítótár)
  redis:
    image: redis:alpine
    container_name: service_finder_redis
    volumes:
      # A Redis snapshot-ok a NAS-ra kerülnek
      - /mnt/nas/app_data/redis_data:/data
    networks:
      - service_finder_net

networks:
  service_finder_net:
    driver: bridge

# Megjegyzés: A lenti volume-okat töröltük, mert "Bind Mount"-ra (direkt útvonalra) váltottunk