# This file was generated by liblab | https://liblab.com/

from typing import List
from .utils.validator import Validator
from .utils.base_service import BaseService
from ..net.transport.serializer import Serializer
from ..models.utils.cast_models import cast_models
from ..models.standings import Standings
from ..models.standing_types import StandingTypes
from ..models.get_standings_by_type_type import GetStandingsByTypeType


class StandingsService(BaseService):

    @cast_models
    def get_standings(self, season: str = None, date_: str = None) -> Standings:
        """get_standings

        :param season: Standings for a specified season., defaults to None
        :type season: str, optional
        :param date_: Standings on a specified date., defaults to None
        :type date_: str, optional
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: OK
        :rtype: Standings
        """

        Validator(str).is_optional().validate(season)
        Validator(str).is_optional().validate(date_)

        serialized_request = (
            Serializer(f"{self.base_url}/standings", self.get_default_headers())
            .add_query("season", season)
            .add_query("date", date_)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return Standings._unmap(response)

    @cast_models
    def get_standings_by_type(self, type_: GetStandingsByTypeType) -> Standings:
        """get_standings_by_type

        :param type_: Standing types:
          * `byConference` - Standings by Conference
          * `byDivision` - Standings by Division
          * `byLeague` - Standings by League
          * `divisionLeaders` - Division Leader standings
          * `postseason` - Postseason Standings
          * `preseason` - Preseason Standings
          * `regularSeason` - Regular Season Standings
          * `wildCard` - Wild card standings
          * `wildCardWithLeaders` - Wild card standings with Division Leaders
        :type type_: GetStandingsByTypeType
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: OK
        :rtype: Standings
        """

        Validator(GetStandingsByTypeType).validate(type_)

        serialized_request = (
            Serializer(
                f"{self.base_url}/standings/{{type}}", self.get_default_headers()
            )
            .add_path("type", type_)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return Standings._unmap(response)

    @cast_models
    def get_standing_types(self) -> List[StandingTypes]:
        """get_standing_types

        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: OK
        :rtype: List[StandingTypes]
        """

        serialized_request = (
            Serializer(f"{self.base_url}/standingsTypes", self.get_default_headers())
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return [StandingTypes._unmap(item) for item in response]
