"""VehiculosModelos Service"""

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


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

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

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

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