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

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.teams import Teams
from ..models.team_stats import TeamStats
from ..models.team import Team
from ..models.rosters import Rosters
from ..models.get_teams_expand import GetTeamsExpand


class TeamsService(BaseService):

    @cast_models
    def get_teams(self, expand: GetTeamsExpand = None, season: float = None) -> Teams:
        """get_teams

        :param expand: Expand your response for some additional data., defaults to None
        :type expand: GetTeamsExpand, optional
        :param season: Return a team's specific season., defaults to None
        :type season: float, optional
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: OK
        :rtype: Teams
        """

        Validator(GetTeamsExpand).is_optional().validate(expand)
        Validator(float).is_optional().validate(season)

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

        response = self.send_request(serialized_request)

        return Teams._unmap(response)

    @cast_models
    def get_team(
        self, id_: float, expand: GetTeamsExpand = None, season: float = None
    ) -> Team:
        """get_team

        :param id_: The ID of the team.
        :type id_: float
        :param expand: Expand your response for some additional data., defaults to None
        :type expand: GetTeamsExpand, optional
        :param season: Return a team's specific season., defaults to None
        :type season: float, optional
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: OK
        :rtype: Team
        """

        Validator(float).validate(id_)
        Validator(GetTeamsExpand).is_optional().validate(expand)
        Validator(float).is_optional().validate(season)

        serialized_request = (
            Serializer(f"{self.base_url}/teams/{{id}}", self.get_default_headers())
            .add_path("id", id_)
            .add_query("expand", expand)
            .add_query("season", season)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return Team._unmap(response)

    @cast_models
    def get_team_roster(self, id_: float, season: float = None) -> Rosters:
        """get_team_roster

        :param id_: The ID of the team.
        :type id_: float
        :param season: Return a team's specific season., defaults to None
        :type season: float, optional
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: OK
        :rtype: Rosters
        """

        Validator(float).validate(id_)
        Validator(float).is_optional().validate(season)

        serialized_request = (
            Serializer(
                f"{self.base_url}/teams/{{id}}/roster", self.get_default_headers()
            )
            .add_path("id", id_)
            .add_query("season", season)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return Rosters._unmap(response)

    @cast_models
    def get_team_stats(self, id_: float) -> TeamStats:
        """get_team_stats

        :param id_: The ID of the team.
        :type id_: float
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: OK
        :rtype: TeamStats
        """

        Validator(float).validate(id_)

        serialized_request = (
            Serializer(
                f"{self.base_url}/teams/{{id}}/stats", self.get_default_headers()
            )
            .add_path("id", id_)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return TeamStats._unmap(response)
