import httpx
import logging

logger = logging.getLogger("DVLA-Service")

class DVLAService:
    API_URL = "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles"
    API_KEY = "IDE_MÁSOLD_BE_AZ_API_KULCSOT"

    @classmethod
    async def get_vehicle_details(cls, vrm: str):
        """VRM az angol rendszám (pl. AB12 CDE)"""
        headers = {
            "x-api-key": cls.API_KEY,
            "Content-Type": "application/json"
        }
        payload = {"registrationNumber": vrm}

        async with httpx.AsyncClient() as client:
            try:
                response = await client.post(cls.API_URL, json=payload, headers=headers)
                if response.status_code == 200:
                    return response.json()
                return None
            except Exception as e:
                logger.error(f"❌ DVLA hiba: {e}")
                return None