"""
Binance Pay REST API

OpenAPI Specification for the Binance Pay REST API
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

import requests
from typing import Optional, TypeVar
from binance_common.configuration import ConfigurationRestAPI
from binance_common.models import ApiResponse
from binance_common.signature import Signers
from binance_common.utils import send_request
from .api.pay_api import PayApi

from .models import GetPayTradeHistoryResponse


T = TypeVar("T")


class PayRestAPI:
    def __init__(
        self,
        configuration: ConfigurationRestAPI,
    ) -> None:
        self.configuration = configuration
        self._session = requests.Session()
        self._signer = (
            Signers.get_signer(
                configuration.private_key, configuration.private_key_passphrase
            )
            if configuration.private_key is not None
            else None
        )

        self._payApi = PayApi(self.configuration, self._session, self._signer)

    def send_request(
        self,
        endpoint: str,
        method: str,
        query_params: Optional[dict] = None,
        body_params: Optional[dict] = None,
    ) -> ApiResponse[T]:
        """
        Sends an request to the Binance REST API.

        Args:
            endpoint (str): The API endpoint path to send the request to.
            method (str): The HTTP method to use for the request (e.g. "GET", "POST", "PUT", "DELETE").
            query_params (Optional[dict]): The request payload as a dictionary, or None if no payload is required.
            body_params (Optional[dict]): The request body as a dictionary, or None if no body is required.

        Returns:
            ApiResponse[T]: The API response, where T is the expected response type.
        """
        return send_request[T](
            self._session,
            self.configuration,
            method,
            endpoint,
            query_params,
            body_params,
        )

    def send_signed_request(
        self,
        endpoint: str,
        method: str,
        query_params: Optional[dict] = None,
        body_params: Optional[dict] = None,
    ) -> ApiResponse[T]:
        """
        Sends a signed request to the Binance REST API.

        Args:
            endpoint (str): The API endpoint path to send the request to.
            method (str): The HTTP method to use for the request (e.g. "GET", "POST", "PUT", "DELETE").
            query_params (Optional[dict]): The request payload as a dictionary, or None if no payload is required.
            body_params (Optional[dict]): The request body as a dictionary, or None if no body is required.

        Returns:
            ApiResponse[T]: The API response, where T is the expected response type.
        """
        return send_request[T](
            self._session,
            self.configuration,
            method,
            endpoint,
            query_params,
            body_params,
            is_signed=True,
            signer=self._signer,
        )

    def get_pay_trade_history(
        self,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        limit: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetPayTradeHistoryResponse]:
        """
                Get Pay Trade History

                Get Pay Trade History

        * If startTime and endTime are not sent, the recent 90 days' data will be returned.
        * The max interval between startTime and endTime is 90 days.
        * Support for querying orders within the last 18 months.
        * For payerInfo and receiverInfo，there are different return values in different orderTypes.
        * Sender's perspective when orderType is C2C
        * payerInfo : binanceId
        * receiverInfo : name, binanceId/accountId/email/countryCode/phoneNumber/mobileCode (based on user input)
        * Receiver's perspective when orderType is C2C
        * payerInfo : name
        * receiverInfo : binanceId
        * Sender's perspective when orderType is CRYPTO_BOX
        * payerInfo : binanceId
        * receiverInfo : name(the value is always "Crypto Box")
        * Receiver's perspective when orderType is CRYPTO_BOX
        * payerInfo : name
        * receiverInfo : binanceId
        * Sender's perspective when orderType is PAY
        * payerInfo : binanceId
        * receiverInfo : name
        * Receiver's perspective when orderType is PAY
        * payerInfo : name
        * receiverInfo : binanceId, name
        * Sender's perspective when orderType is PAY_REFUND
        * payerInfo : binanceId, name
        * receiverInfo : name, accountId
        * Receiver's perspective when orderType is PAY_REFUND
        * payerInfo : name
        * receiverInfo :  binanceId
        * Sender's perspective when orderType is PAYOUT
        * payerInfo : binanceId, name
        * receiverInfo : name, accountId
        * Receiver's perspective when orderType is PAYOUT
        * payerInfo : name
        * receiverInfo :  binanceId
        * Receiver's perspective when orderType is CRYPTO_BOX_RF
        * payerInfo : name(the value is always "Crypto Box")
        * receiverInfo : binanceId
        * Sender's perspective when orderType is REMITTANCE
        * payerInfo : binanceId
        * receiverInfo : name, institutionName, cardNumber, digitalWalletId

        Weight: 3000

                Args:
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    limit (Optional[int] = None): default 100, max 100
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetPayTradeHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        return self._payApi.get_pay_trade_history(
            start_time, end_time, limit, recv_window
        )
