"""
Binance VIP Loan REST API

OpenAPI Specification for the Binance VIP Loan 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 VipLoanBorrowResponse
from ..models import VipLoanRenewResponse
from ..models import VipLoanRepayResponse


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

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

    def vip_loan_borrow(
        self,
        loan_account_id: Union[int, None],
        loan_coin: Union[str, None],
        loan_amount: Union[float, None],
        collateral_account_id: Union[str, None],
        collateral_coin: Union[str, None],
        is_flexible_rate: Union[bool, None],
        loan_term: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[VipLoanBorrowResponse]:
        """
                VIP Loan Borrow(TRADE)
                POST /sapi/v1/loan/vip/borrow
                https://developers.binance.com/docs/vip_loan/trade/VIP-Loan-Borrow

                VIP loan is available for VIP users only.

        * loanAccountId refer to loan receiving account
        * Only master account applications are supported
        * loanAccountId and collateralAccountId under same master account
        * loanTerm is mandatory if user choose stable rate

        Weight: 0

                Args:
                    loan_account_id (Union[int, None]):
                    loan_coin (Union[str, None]):
                    loan_amount (Union[float, None]):
                    collateral_account_id (Union[str, None]): Multiple split by `,`
                    collateral_coin (Union[str, None]): Multiple split by `,`
                    is_flexible_rate (Union[bool, None]): Default: TRUE. TRUE : flexible rate; FALSE: fixed rate
                    loan_term (Optional[int] = None): Mandatory for fixed rate. Optional for fixed interest rate. Eg: 30/60 days
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[VipLoanBorrowResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if loan_account_id is None:
            raise RequiredError(
                field="loan_account_id",
                error_message="Missing required parameter 'loan_account_id'",
            )
        if loan_coin is None:
            raise RequiredError(
                field="loan_coin",
                error_message="Missing required parameter 'loan_coin'",
            )
        if loan_amount is None:
            raise RequiredError(
                field="loan_amount",
                error_message="Missing required parameter 'loan_amount'",
            )
        if collateral_account_id is None:
            raise RequiredError(
                field="collateral_account_id",
                error_message="Missing required parameter 'collateral_account_id'",
            )
        if collateral_coin is None:
            raise RequiredError(
                field="collateral_coin",
                error_message="Missing required parameter 'collateral_coin'",
            )
        if is_flexible_rate is None:
            raise RequiredError(
                field="is_flexible_rate",
                error_message="Missing required parameter 'is_flexible_rate'",
            )

        body = {}
        payload = {
            "loan_account_id": loan_account_id,
            "loan_coin": loan_coin,
            "loan_amount": loan_amount,
            "collateral_account_id": collateral_account_id,
            "collateral_coin": collateral_coin,
            "is_flexible_rate": is_flexible_rate,
            "loan_term": loan_term,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/loan/vip/borrow",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=VipLoanBorrowResponse,
            is_signed=True,
            signer=self._signer,
        )

    def vip_loan_renew(
        self,
        order_id: Union[int, None],
        loan_term: Union[int, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[VipLoanRenewResponse]:
        """
                VIP Loan Renew(TRADE)
                POST /sapi/v1/loan/vip/renew
                https://developers.binance.com/docs/vip_loan/trade/VIP-Loan-Renew

                VIP loan is available for VIP users only.

        Weight: 6000

                Args:
                    order_id (Union[int, None]):
                    loan_term (Union[int, None]): 30/60 days
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[VipLoanRenewResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "order_id": order_id,
            "loan_term": loan_term,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/loan/vip/renew",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=VipLoanRenewResponse,
            is_signed=True,
            signer=self._signer,
        )

    def vip_loan_repay(
        self,
        order_id: Union[int, None],
        amount: Union[float, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[VipLoanRepayResponse]:
        """
                VIP Loan Repay(TRADE)
                POST /sapi/v1/loan/vip/repay
                https://developers.binance.com/docs/vip_loan/trade/VIP-Loan-Repay

                VIP loan is available for VIP users only.

        Weight: 6000

                Args:
                    order_id (Union[int, None]):
                    amount (Union[float, None]):
                    recv_window (Optional[int] = None):

                Returns:
                    ApiResponse[VipLoanRepayResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

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

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/loan/vip/repay",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=VipLoanRepayResponse,
            is_signed=True,
            signer=self._signer,
        )
