"""VehiculosMarcas Service"""

from typing import Optional, List
from ..common import SitarAPIBaseService
from .schemas import VehiculosMarcasResponse


class VehiculosMarcasService(SitarAPIBaseService):
    _instance: Optional["VehiculosMarcasService"] = None

    @classmethod
    def get_instance(cls) -> "VehiculosMarcasService":
        if cls._instance is None:
            cls._instance = cls()
        return cls._instance

    async def search(
        self,
        fraccion: Optional[str] = None,
        marca: Optional[str] = None,
        skip: int = 0,
        limit: int = 100,
    ) -> List[VehiculosMarcasResponse]:
        params = {"skip": skip, "limit": min(limit, 1000)}
        if fraccion:
            params["fraccion"] = fraccion
        if marca:
            params["marca"] = marca
        data = await self._make_request(
            "GET", "/api/v1/vehiculos-marcas/", params=params
        )
        return [VehiculosMarcasResponse(**item) for item in data]

    async def get_by_id(self, sysid: int) -> VehiculosMarcasResponse:
        data = await self._make_request("GET", f"/api/v1/vehiculos-marcas/{sysid}")
        return VehiculosMarcasResponse(**data)
