"""
Binance Dual Investment REST API

OpenAPI Specification for the Binance Dual Investment 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 ChangeAutoCompoundStatusResponse
from ..models import CheckDualInvestmentAccountsResponse
from ..models import GetDualInvestmentPositionsResponse
from ..models import SubscribeDualInvestmentProductsResponse


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 change_auto_compound_status(
        self,
        position_id: Union[str, None],
        auto_compound_plan: Optional[str] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[ChangeAutoCompoundStatusResponse]:
        """
                Change Auto-Compound status(USER_DATA)
                POST /sapi/v1/dci/product/auto_compound/edit-status
                https://developers.binance.com/docs/dual_investment/trade/Change-Auto-Compound-status

                Change Auto-Compound status

        Weight: 1(IP)

                Args:
                    position_id (Union[str, None]): Get positionId from `/sapi/v1/dci/product/positions`
                    auto_compound_plan (Optional[str] = None):
                    recv_window (Optional[int] = None): The value cannot be greater than 60000

                Returns:
                    ApiResponse[ChangeAutoCompoundStatusResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "position_id": position_id,
            "auto_compound_plan": auto_compound_plan,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/dci/product/auto_compound/edit-status",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=ChangeAutoCompoundStatusResponse,
            is_signed=True,
            signer=self._signer,
        )

    def check_dual_investment_accounts(
        self,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[CheckDualInvestmentAccountsResponse]:
        """
                Check Dual Investment accounts(USER_DATA)
                GET /sapi/v1/dci/product/accounts
                https://developers.binance.com/docs/dual_investment/trade/Check-Dual-Investment-accounts

                Check Dual Investment accounts

        Weight: 1(IP)

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

                Returns:
                    ApiResponse[CheckDualInvestmentAccountsResponse]

                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/dci/product/accounts",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=CheckDualInvestmentAccountsResponse,
            is_signed=True,
            signer=self._signer,
        )

    def get_dual_investment_positions(
        self,
        status: Optional[str] = None,
        page_size: Optional[int] = None,
        page_index: Optional[int] = None,
        recv_window: Optional[int] = None,
    ) -> ApiResponse[GetDualInvestmentPositionsResponse]:
        """
                Get Dual Investment positions(USER_DATA)
                GET /sapi/v1/dci/product/positions
                https://developers.binance.com/docs/dual_investment/trade/Get-Dual-Investment-positions

                Get Dual Investment positions (batch)

        Weight: 1(IP)

                Args:
                    status (Optional[str] = None): `PENDING`:Products are purchasing, will give results later;`PURCHASE_SUCCESS`:purchase successfully;`SETTLED`: Products are finish settling;`PURCHASE_FAIL`:fail to purchase;`REFUNDING`:refund ongoing;`REFUND_SUCCESS`:refund to spot account successfully; `SETTLING`:Products are settling. If don't fill this field, will response all the position status.
                    page_size (Optional[int] = None): Default: 10, Maximum: 100
                    page_index (Optional[int] = None): Default: 1
                    recv_window (Optional[int] = None): The value cannot be greater than 60000

                Returns:
                    ApiResponse[GetDualInvestmentPositionsResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = {}
        payload = {
            "status": status,
            "page_size": page_size,
            "page_index": page_index,
            "recv_window": recv_window,
        }

        return send_request(
            self._session,
            self._configuration,
            method="GET",
            path="/sapi/v1/dci/product/positions",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=GetDualInvestmentPositionsResponse,
            is_signed=True,
            signer=self._signer,
        )

    def subscribe_dual_investment_products(
        self,
        id: Union[str, None],
        order_id: Union[str, None],
        deposit_amount: Union[float, None],
        auto_compound_plan: Union[str, None],
        recv_window: Optional[int] = None,
    ) -> ApiResponse[SubscribeDualInvestmentProductsResponse]:
        """
                Subscribe Dual Investment products(USER_DATA)
                POST /sapi/v1/dci/product/subscribe
                https://developers.binance.com/docs/dual_investment/trade/Subscribe-Dual-Investment-products

                Subscribe Dual Investment products

        * Products are not available. // this means APR changes to lower value, or orders are not unavailable.
        * Failed. This means System or network errors.

        Weight: 1(IP)

                Args:
                    id (Union[str, None]): get id from `/sapi/v1/dci/product/list`
                    order_id (Union[str, None]): get orderId from `/sapi/v1/dci/product/list`
                    deposit_amount (Union[float, None]): the amount for subscribing
                    auto_compound_plan (Union[str, None]): `NONE`: switch off the plan, `STANDARD`:standard plan,`ADVANCED`:advanced plan
                    recv_window (Optional[int] = None): The value cannot be greater than 60000

                Returns:
                    ApiResponse[SubscribeDualInvestmentProductsResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

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

        body = {}
        payload = {
            "id": id,
            "order_id": order_id,
            "deposit_amount": deposit_amount,
            "auto_compound_plan": auto_compound_plan,
            "recv_window": recv_window,
        }

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