# /opt/docker/dev/service_finder/backend/app/services/storage_service.py
import uuid
from io import BytesIO
from minio import Minio
from app.core.config import settings

class StorageService:
    # A klienst a beállításokból inicializáljuk
    client = Minio(
        settings.REDIS_URL.split("//")[1].split(":")[0], # Gyors fix a hostra vagy settings.MINIO_HOST
        access_key="minioadmin",
        secret_key="minioadmin",
        secure=False
    )
    BUCKET_NAME = "vehicle-documents"

    @classmethod
    async def upload_document(cls, file_bytes: bytes, file_name: str, folder: str) -> str:
        """ Fájl feltöltése S3/Minio tárhelyre. """
        if not cls.client.bucket_exists(cls.BUCKET_NAME):
            cls.client.make_bucket(cls.BUCKET_NAME)
        
        unique_name = f"{folder}/{uuid.uuid4()}_{file_name}"
        
        cls.client.put_object(
            cls.BUCKET_NAME,
            unique_name,
            BytesIO(file_bytes),
            len(file_bytes)
        )
        return f"{cls.BUCKET_NAME}/{unique_name}"