"""
Binance Simple Earn REST API

OpenAPI Specification for the Binance Simple Earn 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.
"""

from typing import Optional, Union
from requests import Session
from binance_common.configuration import ConfigurationRestAPI
from binance_common.errors import RequiredError
from binance_common.models import ApiResponse
from binance_common.signature import Signers
from binance_common.utils import send_request

from ..models import GetBfusdAccountResponse
from ..models import GetBfusdQuotaDetailsResponse
from ..models import GetBfusdRateHistoryResponse
from ..models import GetBfusdRedemptionHistoryResponse
from ..models import GetBfusdRewardsHistoryResponse
from ..models import GetBfusdSubscriptionHistoryResponse
from ..models import RedeemBfusdResponse
from ..models import SubscribeBfusdResponse


class BfusdApi:
    """API Client for BfusdApi endpoints."""

    def __init__(
        self,
        configuration: ConfigurationRestAPI = None,
        session: Session = None,
        signer: Signers = None,
    ) -> None:
        self._configuration = configuration
        self._session = session
        self._signer = signer

    def get_bfusd_account(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetBfusdAccountResponse]:
        """
                Get BFUSD Account (USER_DATA)
                GET /sapi/v1/bfusd/account
                https://developers.binance.com/docs/simple_earn/bfusd/account/

                Get BFUSD account information.

        Weight: 150

                Args:
                    recv_window (Optional[int] = None): The value cannot be greater than 60000 (ms)

                Returns:
                    ApiResponse[GetBfusdAccountResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/bfusd/account",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetBfusdAccountResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_bfusd_quota_details(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetBfusdQuotaDetailsResponse]:
        """
                Get BFUSD Quota Details (USER_DATA)
                GET /sapi/v1/bfusd/quota
                https://developers.binance.com/docs/simple_earn/bfusd/account/Get-BFUSD-Quota-Details

                Get BFUSD quota details including fast redemption quota and standard redemption quota.

        Weight: 150

                Args:
                    recv_window (Optional[int] = None): The value cannot be greater than 60000 (ms)

                Returns:
                    ApiResponse[GetBfusdQuotaDetailsResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {"recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/bfusd/quota",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetBfusdQuotaDetailsResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_bfusd_rate_history(
        self,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        current: Optional[int] = None,
        size: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetBfusdRateHistoryResponse]:
        """
                Get BFUSD Rate History (USER_DATA)
                GET /sapi/v1/bfusd/history/rateHistory
                https://developers.binance.com/docs/simple_earn/bfusd/history/Get-BFUSD-Rate-History

                Get BFUSD rate history sorted by descending order.

        * The time between `startTime` and `endTime` cannot be longer than 6 months.
        * If `startTime` and `endTime` are both not sent, then the last 30 days' data will be returned.
        * If `startTime` is sent but `endTime` is not sent, `endTime` will default to current time, and results from `startTime` onward will be returned.
        * If `endTime` is sent but `startTime` is not sent, `startTime` defaults to the current time minus one month, and data between `startTime` and `endTime` will be returned.

        Weight: 150

                Args:
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    current (Optional[int] = None): Currently querying page. Starts from 1. Default: 1
                    size (Optional[int] = None): Number of results per page. Default: 10, Max: 100
                    recv_window (Optional[int] = None): The value cannot be greater than 60000 (ms)

                Returns:
                    ApiResponse[GetBfusdRateHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "start_time": start_time,
            "end_time": end_time,
            "current": current,
            "size": size,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/bfusd/history/rateHistory",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetBfusdRateHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_bfusd_redemption_history(
        self,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        current: Optional[int] = None,
        size: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetBfusdRedemptionHistoryResponse]:
        """
                Get BFUSD Redemption History (USER_DATA)
                GET /sapi/v1/bfusd/history/redemptionHistory
                https://developers.binance.com/docs/simple_earn/bfusd/history/Get-BFUSD-Redemption-History

                Get BFUSD redemption history.

        * The time between `startTime` and `endTime` cannot be longer than 6 months.
        * If `startTime` and `endTime` are both not sent, then the last 30 days' data will be returned.
        * If `startTime` is sent but `endTime` is not sent, `endTime` will default to current time, and results from `startTime` onward will be returned.
        * If `endTime` is sent but `startTime` is not sent, `startTime` defaults to the current time minus one month, and data between `startTime` and `endTime` will be returned.

        Weight: 150

                Args:
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    current (Optional[int] = None): Currently querying page. Starts from 1. Default: 1
                    size (Optional[int] = None): Number of results per page. Default: 10, Max: 100
                    recv_window (Optional[int] = None): The value cannot be greater than 60000 (ms)

                Returns:
                    ApiResponse[GetBfusdRedemptionHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "start_time": start_time,
            "end_time": end_time,
            "current": current,
            "size": size,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/bfusd/history/redemptionHistory",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetBfusdRedemptionHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_bfusd_rewards_history(
        self,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        current: Optional[int] = None,
        size: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetBfusdRewardsHistoryResponse]:
        """
                Get BFUSD Rewards History (USER_DATA)
                GET /sapi/v1/bfusd/history/rewardsHistory
                https://developers.binance.com/docs/simple_earn/bfusd/history/Get-BFUSD-Rewards-History

                Get BFUSD rewards history.

        * The time between `startTime` and `endTime` cannot be longer than 6 months.
        * If `startTime` and `endTime` are both not sent, then the last 30 days' data will be returned.
        * If `startTime` is sent but `endTime` is not sent, `endTime` will default to current time, and results from `startTime` onward will be returned.
        * If `endTime` is sent but `startTime` is not sent, `startTime` defaults to the current time minus one month, and data between `startTime` and `endTime` will be returned.

        Weight: 150

                Args:
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    current (Optional[int] = None): Currently querying page. Starts from 1. Default: 1
                    size (Optional[int] = None): Number of results per page. Default: 10, Max: 100
                    recv_window (Optional[int] = None): The value cannot be greater than 60000 (ms)

                Returns:
                    ApiResponse[GetBfusdRewardsHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "start_time": start_time,
            "end_time": end_time,
            "current": current,
            "size": size,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/bfusd/history/rewardsHistory",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetBfusdRewardsHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_bfusd_subscription_history(
        self,
        asset: Optional[str] = None,
        start_time: Optional[int] = None,
        end_time: Optional[int] = None,
        current: Optional[int] = None,
        size: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetBfusdSubscriptionHistoryResponse]:
        """
                Get BFUSD subscription history(USER_DATA)
                GET /sapi/v1/bfusd/history/subscriptionHistory
                https://developers.binance.com/docs/simple_earn/bfusd/history/Get-BFUSD-subscription-history

                Get BFUSD subscription history

        * The time between `startTime` and `endTime` cannot be longer than 6 months.
        * If `startTime` and `endTime` are both not sent, then the last 30 days' data will be returned.
        * If `startTime` is sent but `endTime` is not sent, `endTime` will default to current time, and results from `startTime` onward will be returned.
        * If `endTime` is sent but `startTime` is not sent, `startTime` defaults to the current time advanced by one month, and data between `startTime` and `endTime` will be returned.

        Weight: 150

                Args:
                    asset (Optional[str] = None): USDC or USDT
                    start_time (Optional[int] = None):
                    end_time (Optional[int] = None):
                    current (Optional[int] = None): Currently querying page. Starts from 1. Default: 1
                    size (Optional[int] = None): Number of results per page. Default: 10, Max: 100
                    recv_window (Optional[int] = None): The value cannot be greater than 60000 (ms)

                Returns:
                    ApiResponse[GetBfusdSubscriptionHistoryResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "asset": asset,
            "start_time": start_time,
            "end_time": end_time,
            "current": current,
            "size": size,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/bfusd/history/subscriptionHistory",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetBfusdSubscriptionHistoryResponse,
            is_signed=True,
            signer=self._signer,
        )

    def redeem_bfusd(
        self,
        amount: Union[float, None],
        type: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[RedeemBfusdResponse]:
        """
                Redeem BFUSD(TRADE)
                POST /sapi/v1/bfusd/redeem
                https://developers.binance.com/docs/simple_earn/bfusd/earn/Redeem-BFUSD

                Redeem BFUSD to USDT

        * You need to open Enable Spot & Margin Trading permission for the API Key which requests this endpoint.

        Weight: 150

                Args:
                    amount (Union[float, None]): Amount
                    type (Union[str, None]): FAST or STANDARD, defaults to STANDARD
                    recv_window (Optional[int] = None): The value cannot be greater than 60000 (ms)

                Returns:
                    ApiResponse[RedeemBfusdResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if amount is None:
            raise RequiredError(
                field="amount", error_message="Missing required parameter 'amount'"
            )
        if type is None:
            raise RequiredError(
                field="type", error_message="Missing required parameter 'type'"
            )

        body = {}
        payload = {"amount": amount, "type": type, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/bfusd/redeem",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=RedeemBfusdResponse,
            is_signed=True,
            signer=self._signer,
        )

    def subscribe_bfusd(
        self,
        asset: Union[str, None],
        amount: Union[float, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[SubscribeBfusdResponse]:
        """
                Subscribe BFUSD(TRADE)
                POST /sapi/v1/bfusd/subscribe
                https://developers.binance.com/docs/simple_earn/bfusd/earn/Subscribe-BFUSD

                Subscribe BFUSD

        * You need to open Enable Spot & Margin Trading permission for the API Key which requests this endpoint.

        Weight: 150

                Args:
                    asset (Union[str, None]): USDT or USDC (whichever is eligible)
                    amount (Union[float, None]): Amount
                    recv_window (Optional[int] = None): The value cannot be greater than 60000 (ms)

                Returns:
                    ApiResponse[SubscribeBfusdResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if asset is None:
            raise RequiredError(
                field="asset", error_message="Missing required parameter 'asset'"
            )
        if amount is None:
            raise RequiredError(
                field="amount", error_message="Missing required parameter 'amount'"
            )

        body = {}
        payload = {"asset": asset, "amount": amount, "recv_window": recv_window}

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/bfusd/subscribe",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=SubscribeBfusdResponse,
            is_signed=True,
            signer=self._signer,
        )
