<?php

/**
 * AccountApiTest
 * PHP version 8.1.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Binance Derivatives Trading Portfolio Margin Pro REST API.
 *
 * OpenAPI Specification for the Binance Derivatives Trading Portfolio Margin Pro REST API
 *
 * The version of the OpenAPI document: 1.0.0
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.12.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Please update the test case below to test the endpoint.
 */

namespace Binance\Client\DerivativesTradingPortfolioMarginPro\Test\Api;

use Binance\Client\DerivativesTradingPortfolioMarginPro\Api\AccountApi;
use Binance\Client\DerivativesTradingPortfolioMarginPro\Model\BnbTransferRequest;
use Binance\Client\DerivativesTradingPortfolioMarginPro\Model\ChangeAutoRepayFuturesStatusRequest;
use Binance\Client\DerivativesTradingPortfolioMarginPro\Model\FundAutoCollectionRequest;
use Binance\Client\DerivativesTradingPortfolioMarginPro\Model\FundCollectionByAssetRequest;
use Binance\Client\DerivativesTradingPortfolioMarginPro\Model\MintBfusdForPortfolioMarginRequest;
use Binance\Client\DerivativesTradingPortfolioMarginPro\Model\PortfolioMarginProBankruptcyLoanRepayRequest;
use Binance\Client\DerivativesTradingPortfolioMarginPro\Model\RedeemBfusdForPortfolioMarginRequest;
use Binance\Client\DerivativesTradingPortfolioMarginPro\Model\RepayFuturesNegativeBalanceRequest;
use Binance\Client\DerivativesTradingPortfolioMarginPro\Model\TransferLdusdtForPortfolioMarginRequest;
use Binance\Common\Configuration\ClientConfiguration;
use Binance\Common\Configuration\SignatureConfiguration;
use Binance\Common\HttpClient;
use GuzzleHttp\Psr7\Utils;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;

/**
 * AccountApiTest Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @internal
 *
 * @coversNothing
 */
class AccountApiTest extends TestCase
{
    public function getApiMock(&$request)
    {
        $clientMock = $this->createMock(HttpClient::class);
        $signatureConfig = new SignatureConfiguration();
        $signatureConfig->setApiKey('apiKey');
        $signatureConfig->setSecretKey('secretKey');
        $clientConfig = new ClientConfiguration();
        $clientConfig->setUrl('http://localhost:8080');
        $clientConfig->setSignatureConfiguration($signatureConfig);
        $responseMock = $this->createMock(ResponseInterface::class);

        $responseMock->expects($this->any())
            ->method('getStatusCode')
            ->willReturn(200)
        ;

        $responseMock->expects($this->any())
            ->method('getBody')
            ->willReturn(Utils::streamFor('{}'))
        ;

        $clientMock->expects($this->once())
            ->method('send')
            ->will($this->returnCallback(function ($actualRequest) use (&$request, $responseMock) {
                $request = $actualRequest;

                return $responseMock;
            }))
        ;

        $apiMock = $this->getMockBuilder(AccountApi::class)
            ->setConstructorArgs([$clientConfig, $clientMock])
            ->onlyMethods(['getTimestamp'])
            ->getMock()
        ;

        $apiMock->method('getTimestamp')->willReturn('1736393892000');

        return $apiMock;
    }

    /**
     * Test case for bnbTransfer.
     *
     * BNB transfer(USER_DATA).
     */
    public function testBnbTransfer()
    {
        $bnbTransferRequest = new BnbTransferRequest();
        $bnbTransferRequest->setAmount(1.0);
        $bnbTransferRequest->setTransferSide('');

        $response = $this->getApiMock($request)->bnbTransfer($bnbTransferRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/bnb-transfer', $request->getUri()->getPath());
        self::assertEquals('50d24733794b928836575c346769be26ee1fb5ffbf73f36933cd22c50116f74e', $queryMap['signature']);
    }

    /**
     * Test case for changeAutoRepayFuturesStatus.
     *
     * Change Auto-repay-futures Status(TRADE).
     */
    public function testChangeAutoRepayFuturesStatus()
    {
        $changeAutoRepayFuturesStatusRequest = new ChangeAutoRepayFuturesStatusRequest();
        $changeAutoRepayFuturesStatusRequest->setAutoRepay('');

        $response = $this->getApiMock($request)->changeAutoRepayFuturesStatus($changeAutoRepayFuturesStatusRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/repay-futures-switch', $request->getUri()->getPath());
        self::assertEquals('da82fc30a786fb2fea807a0c84e13082bdf837e1bcdd4ec170d79b99f48d8386', $queryMap['signature']);
    }

    /**
     * Test case for fundAutoCollection.
     *
     * Fund Auto-collection(USER_DATA).
     */
    public function testFundAutoCollection()
    {
        $fundAutoCollectionRequest = new FundAutoCollectionRequest();

        $response = $this->getApiMock($request)->fundAutoCollection($fundAutoCollectionRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/auto-collection', $request->getUri()->getPath());
        self::assertEquals('dc0def720e795be0f84b02a8fa211ecc3a27dd06ffdbd287a679f1321807f820', $queryMap['signature']);
    }

    /**
     * Test case for fundCollectionByAsset.
     *
     * Fund Collection by Asset(USER_DATA).
     */
    public function testFundCollectionByAsset()
    {
        $fundCollectionByAssetRequest = new FundCollectionByAssetRequest();
        $fundCollectionByAssetRequest->setAsset('');

        $response = $this->getApiMock($request)->fundCollectionByAsset($fundCollectionByAssetRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/asset-collection', $request->getUri()->getPath());
        self::assertEquals('2979a51ce4c44a35c65db4a87fdd907b27c5f1cb4e786af718af1c6bceff4ce0', $queryMap['signature']);
    }

    /**
     * Test case for getAutoRepayFuturesStatus.
     *
     * Get Auto-repay-futures Status(USER_DATA).
     */
    public function testGetAutoRepayFuturesStatus()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getAutoRepayFuturesStatus($recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/repay-futures-switch', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for getPortfolioMarginProAccountBalance.
     *
     * Get Portfolio Margin Pro Account Balance(USER_DATA).
     */
    public function testGetPortfolioMarginProAccountBalance()
    {
        $asset = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getPortfolioMarginProAccountBalance($asset, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/balance', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for getPortfolioMarginProAccountInfo.
     *
     * Get Portfolio Margin Pro Account Info(USER_DATA).
     */
    public function testGetPortfolioMarginProAccountInfo()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getPortfolioMarginProAccountInfo($recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/account', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for getPortfolioMarginProSpanAccountInfo.
     *
     * Get Portfolio Margin Pro SPAN Account Info(USER_DATA).
     */
    public function testGetPortfolioMarginProSpanAccountInfo()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getPortfolioMarginProSpanAccountInfo($recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/portfolio/account', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for getTransferableEarnAssetBalanceForPortfolioMargin.
     *
     * Get Transferable Earn Asset Balance for Portfolio Margin (USER_DATA).
     */
    public function testGetTransferableEarnAssetBalanceForPortfolioMargin()
    {
        $asset = '';
        $transferType = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getTransferableEarnAssetBalanceForPortfolioMargin($asset, $transferType, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/earn-asset-balance', $request->getUri()->getPath());
        self::assertEquals('26929f698a8abc46101bb3b2f06b0b52e0b0e8876ecda502637a89146ebd193e', $queryMap['signature']);
    }

    /**
     * Test case for mintBfusdForPortfolioMargin.
     *
     * Mint BFUSD for Portfolio Margin(TRADE).
     */
    public function testMintBfusdForPortfolioMargin()
    {
        $mintBfusdForPortfolioMarginRequest = new MintBfusdForPortfolioMarginRequest();
        $mintBfusdForPortfolioMarginRequest->setFromAsset('');
        $mintBfusdForPortfolioMarginRequest->setTargetAsset('');
        $mintBfusdForPortfolioMarginRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->mintBfusdForPortfolioMargin($mintBfusdForPortfolioMarginRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/mint', $request->getUri()->getPath());
        self::assertEquals('50d24733794b928836575c346769be26ee1fb5ffbf73f36933cd22c50116f74e', $queryMap['signature']);
    }

    /**
     * Test case for portfolioMarginProBankruptcyLoanRepay.
     *
     * Portfolio Margin Pro Bankruptcy Loan Repay.
     */
    public function testPortfolioMarginProBankruptcyLoanRepay()
    {
        $portfolioMarginProBankruptcyLoanRepayRequest = new PortfolioMarginProBankruptcyLoanRepayRequest();

        $response = $this->getApiMock($request)->portfolioMarginProBankruptcyLoanRepay($portfolioMarginProBankruptcyLoanRepayRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/repay', $request->getUri()->getPath());
        self::assertEquals('dc0def720e795be0f84b02a8fa211ecc3a27dd06ffdbd287a679f1321807f820', $queryMap['signature']);
    }

    /**
     * Test case for queryPortfolioMarginProBankruptcyLoanAmount.
     *
     * Query Portfolio Margin Pro Bankruptcy Loan Amount(USER_DATA).
     */
    public function testQueryPortfolioMarginProBankruptcyLoanAmount()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryPortfolioMarginProBankruptcyLoanAmount($recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/pmLoan', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for queryPortfolioMarginProBankruptcyLoanRepayHistory.
     *
     * Query Portfolio Margin Pro Bankruptcy Loan Repay History(USER_DATA).
     */
    public function testQueryPortfolioMarginProBankruptcyLoanRepayHistory()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryPortfolioMarginProBankruptcyLoanRepayHistory($startTime, $endTime, $current, $size, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/pmloan-history', $request->getUri()->getPath());
        self::assertEquals('2ecc0415a3bdb2963e8030cdf6cf00de6f49d21b71ff939dda42e5756eb8ba66', $queryMap['signature']);
    }

    /**
     * Test case for queryPortfolioMarginProNegativeBalanceInterestHistory.
     *
     * Query Portfolio Margin Pro Negative Balance Interest History(USER_DATA).
     */
    public function testQueryPortfolioMarginProNegativeBalanceInterestHistory()
    {
        $asset = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryPortfolioMarginProNegativeBalanceInterestHistory($asset, $startTime, $endTime, $size, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/interest-history', $request->getUri()->getPath());
        self::assertEquals('61a296b6ab8d4cc785e344506d988c939cdbed5c43f133c27db572231eaac2e1', $queryMap['signature']);
    }

    /**
     * Test case for redeemBfusdForPortfolioMargin.
     *
     * Redeem BFUSD for Portfolio Margin(TRADE).
     */
    public function testRedeemBfusdForPortfolioMargin()
    {
        $redeemBfusdForPortfolioMarginRequest = new RedeemBfusdForPortfolioMarginRequest();
        $redeemBfusdForPortfolioMarginRequest->setFromAsset('');
        $redeemBfusdForPortfolioMarginRequest->setTargetAsset('');
        $redeemBfusdForPortfolioMarginRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->redeemBfusdForPortfolioMargin($redeemBfusdForPortfolioMarginRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/redeem', $request->getUri()->getPath());
        self::assertEquals('50d24733794b928836575c346769be26ee1fb5ffbf73f36933cd22c50116f74e', $queryMap['signature']);
    }

    /**
     * Test case for repayFuturesNegativeBalance.
     *
     * Repay futures Negative Balance(USER_DATA).
     */
    public function testRepayFuturesNegativeBalance()
    {
        $repayFuturesNegativeBalanceRequest = new RepayFuturesNegativeBalanceRequest();

        $response = $this->getApiMock($request)->repayFuturesNegativeBalance($repayFuturesNegativeBalanceRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/repay-futures-negative-balance', $request->getUri()->getPath());
        self::assertEquals('dc0def720e795be0f84b02a8fa211ecc3a27dd06ffdbd287a679f1321807f820', $queryMap['signature']);
    }

    /**
     * Test case for transferLdusdtForPortfolioMargin.
     *
     * Transfer LDUSDT for Portfolio Margin(TRADE).
     */
    public function testTransferLdusdtForPortfolioMargin()
    {
        $transferLdusdtForPortfolioMarginRequest = new TransferLdusdtForPortfolioMarginRequest();
        $transferLdusdtForPortfolioMarginRequest->setAsset('');
        $transferLdusdtForPortfolioMarginRequest->setTransferType('');
        $transferLdusdtForPortfolioMarginRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->transferLdusdtForPortfolioMargin($transferLdusdtForPortfolioMarginRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/portfolio/earn-asset-transfer', $request->getUri()->getPath());
        self::assertEquals('50d24733794b928836575c346769be26ee1fb5ffbf73f36933cd22c50116f74e', $queryMap['signature']);
    }
}
