"""
Binance Fiat REST API

OpenAPI Specification for the Binance Fiat 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, Union
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.fiat_api import FiatApi

from .models import DepositResponse
from .models import FiatWithdrawResponse
from .models import GetFiatDepositWithdrawHistoryResponse
from .models import GetFiatPaymentsHistoryResponse
from .models import GetOrderDetailResponse

from .models import AccountInfo


T = TypeVar("T")


class FiatRestAPI:
    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._fiatApi = FiatApi(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 deposit(
        self,
        currency: Union[str, None],
        api_payment_method: Union[str, None],
        amount: Union[int, None],
        recv_window: Optional[int] = None,
        ext: Optional[object] = None,
    ) -> ApiResponse[DepositResponse]:
        """
                Deposit(TRADE)

                Submit deposit request, in this version, we only support BRL deposit via pix.



        For BRL deposit via pix, you need to place an order before making a transfer from your bank.

        Before calling this api, please make sure you have already completed your KYC or KYB, and already activated your fiat service on our website.

        Weight: 45000

                Args:
                    currency (Union[str, None]):
                    api_payment_method (Union[str, None]):
                    amount (Union[int, None]):
                    recv_window (Optional[int] = None):
                    ext (Optional[object] = None):

                Returns:
                    ApiResponse[DepositResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        return self._fiatApi.deposit(
            currency, api_payment_method, amount, recv_window, ext
        )

    def fiat_withdraw(
        self,
        currency: Union[str, None],
        api_payment_method: Union[str, None],
        amount: Union[int, None],
        account_info: Union[AccountInfo, None],
        recv_window: Optional[int] = None,
        ext: Optional[object] = None,
    ) -> ApiResponse[FiatWithdrawResponse]:
        """
                Fiat Withdraw(WITHDRAW)

                Submit withdraw request, in this version, we only support BRL withdrawal via bank_transfer.

        You need to call this api first, and call query order detail api in a loop to get the status of the order until this order is successful.

        Before calling this api, please make sure you have already completed your KYC or KYB, and already activated your fiat service on our website.

        you need to bind your bank account on web/app before using the corresponding account number

        Weight: 45000

                Args:
                    currency (Union[str, None]):
                    api_payment_method (Union[str, None]):
                    amount (Union[int, None]):
                    account_info (Union[AccountInfo, None]):
                    recv_window (Optional[int] = None):
                    ext (Optional[object] = None):

                Returns:
                    ApiResponse[FiatWithdrawResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        return self._fiatApi.fiat_withdraw(
            currency, api_payment_method, amount, account_info, recv_window, ext
        )

    def get_fiat_deposit_withdraw_history(
        self,
        transaction_type: Union[str, None],
        begin_time: Optional[int] = None,
        end_time: Optional[int] = None,
        page: Optional[int] = None,
        rows: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetFiatDepositWithdrawHistoryResponse]:
        """
                Get Fiat Deposit/Withdraw History (USER_DATA)

                Get Fiat Deposit/Withdraw History

        * If beginTime and endTime are not sent, the recent 30-day data will be returned.

        Weight: 45000

                Args:
                    transaction_type (Union[str, None]): 0-buy,1-sell
                    begin_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    page (Optional[int] = None): default 1
                    rows (Optional[int] = None): default 100, max 500
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetFiatDepositWithdrawHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        return self._fiatApi.get_fiat_deposit_withdraw_history(
            transaction_type, begin_time, end_time, page, rows, recv_window
        )

    def get_fiat_payments_history(
        self,
        transaction_type: Union[str, None],
        begin_time: Optional[int] = None,
        end_time: Optional[int] = None,
        page: Optional[int] = None,
        rows: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetFiatPaymentsHistoryResponse]:
        """
                Get Fiat Payments History (USER_DATA)

                Get Fiat Deposit/Withdraw History

        * If beginTime and endTime are not sent, the recent 30-day data will be returned.
        * paymentMethod: Only when requesting payments history for buy (transactionType=0), response contains paymentMethod representing the way of purchase. Now we have:
        * Cash Balance
        * Credit Card
        * Online Banking
        * Bank Transfer

        Weight: 1

                Args:
                    transaction_type (Union[str, None]): 0-buy,1-sell
                    begin_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    page (Optional[int] = None): default 1
                    rows (Optional[int] = None): default 100, max 500
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetFiatPaymentsHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        return self._fiatApi.get_fiat_payments_history(
            transaction_type, begin_time, end_time, page, rows, recv_window
        )

    def get_order_detail(
        self,
        order_no: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetOrderDetailResponse]:
        """
                Get Order Detail(USER_DATA)

                Get Order Detail

        Before calling this api, please make sure you have already completed your KYC or KYB, and already activated your fiat service on our website.

        Weight: 1

                Args:
                    order_no (Union[str, None]): order id retrieved from the api call of withdrawal
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[GetOrderDetailResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        return self._fiatApi.get_order_detail(order_no, recv_window)
