# 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.sort_dir import SortDir
from ..models.get_bets_by_type_response_v4 import GetBetsByTypeResponseV4
from ..models.bets_get_bets_by_type_v4_bet_type import BetsGetBetsByTypeV4BetType
from ..models.betlist import Betlist
from ..models.bet_statuses import BetStatuses


class GetBetsService(BaseService):

    @cast_models
    def bets_get_bets_by_type_v4(
        self,
        betlist: Betlist = None,
        bet_statuses: List[BetStatuses] = None,
        from_date: str = None,
        to_date: str = None,
        sort_dir: SortDir = None,
        page_size: int = None,
        from_record: int = None,
        betids: List[int] = None,
        unique_request_ids: List[str] = None,
        bet_type: List[BetsGetBetsByTypeV4BetType] = None,
    ) -> GetBetsByTypeResponseV4:
        """Returns bets.


        ### Get running bets by time range:
        ```
        https://api.pinnacle.com/v4/bets?betlist=RUNNING&fromDate=2017-11-21T00:00:00Z&toDate=2017-11-29T00:00:00Z
        ```
        Running bets are queried by *placedAt* date time


        ### Get settled bets by time range:

        ```
        https://api.pinnacle.com/v4/bets?betlist=SETTLED&fromDate=2015-12-28T00:00:00Z&toDate=2015-12-29T00:00:00Z
        ```
        Settled bets are queried by *settledAt* date time
        https://api.pinnacle.com/v4/bets?betlist=SETTLED&fromDate=2017-11-20T00:00:00Z&toDate=2017-11-23T00:00:00Z


        ### Get settled cancelled bets by time range:

        ```
        https://api.pinnacle.com/v4/bets?betList=SETTLED&fromDate=2018-03-01&toDate=2018-03-28&betStatuses=CANCELLED
        ```


        ### Get bets by bet ids:

        ```
        https://api.pinnacle.com/v4/bets?betIds=775856112,775856113,775856114
        ```

        ### Get bets by uniqueRequestIds:

        ```
        https://api.pinnacle.com/v4/bets?uniqueRequestIds=62335222-dae4-479a-8c05-46440ccdd3bb,42335222-dae4-479a-8c05-46440ccdd3bb
        ```

        :param betlist: Type of bet list to return. Not needed when betids is submitted., defaults to None
        :type betlist: Betlist, optional
        :param bet_statuses: Type of bet statues to return. This works only in conjustion with betlist, as additional filter., defaults to None
        :type bet_statuses: List[BetStatuses], optional
        :param from_date: Start date of the requested period. Required when betlist parameter is submitted. Start date can be up to 30 days in the past. Expected format is ISO8601 - can be set to just date or date and time., defaults to None
        :type from_date: str, optional
        :param to_date: End date of the requested period. Required when betlist parameter is submitted. Expected format is ISO8601 - can be set to just date or date and time.  toDate value is exclusive, meaning it cannot be equal to fromDate., defaults to None
        :type to_date: str, optional
        :param sort_dir: Sort direction by postedAt/settledAt. Respected only when querying by date range., defaults to None
        :type sort_dir: SortDir, optional
        :param page_size: Page size in case. Max is 1000. Respected only when querying by date range., defaults to None
        :type page_size: int, optional
        :param from_record: Starting record (inclusive) of the result. Respected only when querying by date range. To fetch next page set it to toRecord+1, defaults to None
        :type from_record: int, optional
        :param betids: A comma separated list of bet ids. When betids is submitted, no other parameter is necessary. Maximum is 100 ids. Works for all non settled bets and all bets settled in the last 30 days., defaults to None
        :type betids: List[int], optional
        :param unique_request_ids: A comma separated list of `uniqueRequestId` from the place bet request. If specified, it's highest priority, all other parameters are ignored. Maximum is 10 ids. If client has bet id, preferred way is to use `betIds` query parameter, you can use `uniqueRequestIds` when you do not  have bet id.
        That are 2 cases when client may not have a bet id:

        1. When you bet on live event with live delay, place bet response in that case does not return bet id, so client can query bet status by `uniqueRequestIds`.
        2. In case of any network issues when client is not sure what happened with his place bet request. Empty response means that the bet was not placed. Please check [Deduplication section](https://www.pinnacle.com/de/api/manual#overview) for more details.

        Note that there is a restriction: querying by uniqueRequestIds  is supported for straight and  special bets and only up to 30 min from the moment the bet was place., defaults to None
        :type unique_request_ids: List[str], optional
        :param bet_type: A comma separated list of bet types., defaults to None
        :type bet_type: List[BetsGetBetsByTypeV4BetType], optional
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: OK
        :rtype: GetBetsByTypeResponseV4
        """

        Validator(Betlist).is_optional().validate(betlist)
        Validator(BetStatuses).is_array().is_optional().validate(bet_statuses)
        Validator(str).is_optional().validate(from_date)
        Validator(str).is_optional().validate(to_date)
        Validator(SortDir).is_optional().validate(sort_dir)
        Validator(int).is_optional().validate(page_size)
        Validator(int).is_optional().validate(from_record)
        Validator(int).is_array().is_optional().validate(betids)
        Validator(str).is_array().is_optional().validate(unique_request_ids)
        Validator(BetsGetBetsByTypeV4BetType).is_array().is_optional().validate(
            bet_type
        )

        serialized_request = (
            Serializer(f"{self.base_url}/v4/bets", self.get_default_headers())
            .add_query("betlist", betlist)
            .add_query("betStatuses", bet_statuses, explode=False)
            .add_query("fromDate", from_date)
            .add_query("toDate", to_date)
            .add_query("sortDir", sort_dir)
            .add_query("pageSize", page_size)
            .add_query("fromRecord", from_record)
            .add_query("betids", betids, explode=False)
            .add_query("uniqueRequestIds", unique_request_ids, explode=False)
            .add_query("betType", bet_type, explode=False)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return GetBetsByTypeResponseV4._unmap(response)
