# 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.schedule import Schedule
from ..models.get_schedule_expand import GetScheduleExpand


class ScheduleService(BaseService):

    @cast_models
    def get_schedule(
        self,
        expand: GetScheduleExpand = None,
        team_id: str = None,
        start_date: str = None,
        end_date: str = None,
    ) -> Schedule:
        """get_schedule

        :param expand: Expand explanations:
          * `schedule.brodcasts` - Shows the broadcasts of the game.
          * `schedule.linescore` - Linescore for completed games.
          * `schedule.ticket` - Provides the different places to buy tickets for the upcoming games.
          * `team.schedule.previous` - Same as above but for the last game played., defaults to None
        :type expand: GetScheduleExpand, optional
        :param team_id: Limit results to a specific team. Team ids can be found through the teams endpoint, defaults to None
        :type team_id: str, optional
        :param start_date: Start date for the search., defaults to None
        :type start_date: str, optional
        :param end_date: End date for the search., defaults to None
        :type end_date: str, optional
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: OK
        :rtype: Schedule
        """

        Validator(GetScheduleExpand).is_optional().validate(expand)
        Validator(str).is_optional().validate(team_id)
        Validator(str).is_optional().validate(start_date)
        Validator(str).is_optional().validate(end_date)

        serialized_request = (
            Serializer(f"{self.base_url}/schedule", self.get_default_headers())
            .add_query("expand", expand)
            .add_query("teamId", team_id)
            .add_query("startDate", start_date)
            .add_query("endDate", end_date)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return Schedule._unmap(response)
