# 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.players import Players
from ..models.player_stats import PlayerStats
from ..models.get_player_stats_stats import GetPlayerStatsStats


class PlayersService(BaseService):

    @cast_models
    def get_player(self, id_: float) -> Players:
        """get_player

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

        Validator(float).validate(id_)

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

        response = self.send_request(serialized_request)

        return Players._unmap(response)

    @cast_models
    def get_player_stats(
        self, id_: float, stats: GetPlayerStatsStats, season: float = None
    ) -> PlayerStats:
        """get_player_stats

        :param id_: The ID of the player.
        :type id_: float
        :param stats: Stats explanations:
          * `homeAndAway` - Provides a split between home and away games.
          * `byMonth` - Monthly split of stats.
          * `byDayOfWeek` - Split done by day of the week.
          * `goalsByGameSituation` - Shows number on when goals for a player happened like how many in the shootout, how many in each period, etc.
          * `onPaceRegularSeason` - This only works with the current in-progress season and shows projected totals based on current onPaceRegularSeason.
          * `regularSeasonStatRankings` - Returns where someone stands vs the rest of the league for a specific regularSeasonStatRankings
          * `statsSingleSeason` - Obtains single season statistics for a player.
          * `vsConference` - Conference stats split.
          * `vsDivision` - Division stats split.
          * `vsTeam` - Conference stats split.
          * `winLoss` - Very similar to the previous modifier except it provides the W/L/OT split instead of Home and Away.
        :type stats: GetPlayerStatsStats
        :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: PlayerStats
        """

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

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

        response = self.send_request(serialized_request)

        return PlayerStats._unmap(response)
