<?php

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

/**
 * Binance Sub Account REST API.
 *
 * OpenAPI Specification for the Binance Sub Account 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\SubAccount\Test\Api;

use Binance\Client\SubAccount\Api\AssetManagementApi;
use Binance\Client\SubAccount\Model\FuturesTransferForSubAccountRequest;
use Binance\Client\SubAccount\Model\MarginTransferForSubAccountRequest;
use Binance\Client\SubAccount\Model\MovePositionForSubAccountRequest;
use Binance\Client\SubAccount\Model\OrderArgs;
use Binance\Client\SubAccount\Model\SubAccountFuturesAssetTransferRequest;
use Binance\Client\SubAccount\Model\TransferToMasterRequest;
use Binance\Client\SubAccount\Model\TransferToSubAccountOfSameMasterRequest;
use Binance\Client\SubAccount\Model\UniversalTransferRequest;
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;

/**
 * AssetManagementApiTest Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @internal
 *
 * @coversNothing
 */
class AssetManagementApiTest 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(AssetManagementApi::class)
            ->setConstructorArgs([$clientConfig, $clientMock])
            ->onlyMethods(['getTimestamp'])
            ->getMock()
        ;

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

        return $apiMock;
    }

    /**
     * Test case for futuresTransferForSubAccount.
     *
     * Futures Transfer for Sub-account (For Master Account) (USER_DATA).
     */
    public function testFuturesTransferForSubAccount()
    {
        $futuresTransferForSubAccountRequest = new FuturesTransferForSubAccountRequest();
        $futuresTransferForSubAccountRequest->setEmail('sub-account-email@email.com');
        $futuresTransferForSubAccountRequest->setAsset('');
        $futuresTransferForSubAccountRequest->setAmount(1.0);
        $futuresTransferForSubAccountRequest->setType(1);

        $response = $this->getApiMock($request)->futuresTransferForSubAccount($futuresTransferForSubAccountRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/sub-account/futures/transfer', $request->getUri()->getPath());
        self::assertEquals('b4be732ba42c0f53afd68a041c98176ce8a169c8c1e8257cfb8a64bc5f92cb90', $queryMap['signature']);
    }

    /**
     * Test case for getDetailOnSubAccountsFuturesAccount.
     *
     * Get Detail on Sub-account's Futures Account (For Master Account) (USER_DATA).
     */
    public function testGetDetailOnSubAccountsFuturesAccount()
    {
        $email = 'sub-account-email@email.com';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getDetailOnSubAccountsFuturesAccount($email, $recvWindow);

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

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

    /**
     * Test case for getDetailOnSubAccountsFuturesAccountV2.
     *
     * Get Detail on Sub-account's Futures Account V2 (For Master Account) (USER_DATA).
     */
    public function testGetDetailOnSubAccountsFuturesAccountV2()
    {
        $email = 'sub-account-email@email.com';
        $futuresType = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getDetailOnSubAccountsFuturesAccountV2($email, $futuresType, $recvWindow);

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

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

    /**
     * Test case for getDetailOnSubAccountsMarginAccount.
     *
     * Get Detail on Sub-account's Margin Account (For Master Account) (USER_DATA).
     */
    public function testGetDetailOnSubAccountsMarginAccount()
    {
        $email = 'sub-account-email@email.com';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getDetailOnSubAccountsMarginAccount($email, $recvWindow);

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

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

    /**
     * Test case for getMovePositionHistoryForSubAccount.
     *
     * Get Move Position History for Sub-account (For Master Account) (USER_DATA).
     */
    public function testGetMovePositionHistoryForSubAccount()
    {
        $symbol = '';
        $page = 1;
        $row = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getMovePositionHistoryForSubAccount($symbol, $page, $row, $startTime, $endTime, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/sub-account/futures/move-position', $request->getUri()->getPath());
        self::assertEquals('a22d6220facbcdfebab9cd9e028023cffccb3da50a85062d3821a6ae9cd05f91', $queryMap['signature']);
    }

    /**
     * Test case for getSubAccountDepositAddress.
     *
     * Get Sub-account Deposit Address (For Master Account) (USER_DATA).
     */
    public function testGetSubAccountDepositAddress()
    {
        $email = 'sub-account-email@email.com';
        $coin = '';
        $network = '';
        $amount = 1.0;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSubAccountDepositAddress($email, $coin, $network, $amount, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/capital/deposit/subAddress', $request->getUri()->getPath());
        self::assertEquals('ede80d2daca3e79209f84f7a3cc1e4a1111629c02846b3247e98e4379d6c4ce5', $queryMap['signature']);
    }

    /**
     * Test case for getSubAccountDepositHistory.
     *
     * Get Sub-account Deposit History (For Master Account) (USER_DATA).
     */
    public function testGetSubAccountDepositHistory()
    {
        $email = 'sub-account-email@email.com';
        $coin = '';
        $status = null;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 1;
        $offset = 0;
        $recvWindow = 5000;
        $txId = '1';
        $response = $this->getApiMock($request)->getSubAccountDepositHistory($email, $coin, $status, $startTime, $endTime, $limit, $offset, $recvWindow, $txId);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/capital/deposit/subHisrec', $request->getUri()->getPath());
        self::assertEquals('8e9ec2d2951d7b1d365e61910ee2fadd7ebff4ffccfa6ce8155addaa2ec1d9eb', $queryMap['signature']);
    }

    /**
     * Test case for getSummaryOfSubAccountsFuturesAccount.
     *
     * Get Summary of Sub-account's Futures Account (For Master Account) (USER_DATA).
     */
    public function testGetSummaryOfSubAccountsFuturesAccount()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSummaryOfSubAccountsFuturesAccount($recvWindow);

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

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

    /**
     * Test case for getSummaryOfSubAccountsFuturesAccountV2.
     *
     * Get Summary of Sub-account's Futures Account V2 (For Master Account) (USER_DATA).
     */
    public function testGetSummaryOfSubAccountsFuturesAccountV2()
    {
        $futuresType = 1;
        $page = 1;
        $limit = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSummaryOfSubAccountsFuturesAccountV2($futuresType, $page, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/sub-account/futures/accountSummary', $request->getUri()->getPath());
        self::assertEquals('7d9b20a8e752a66e488f88e0beb869b57d666a10184ecc2873c4549a4afa5f18', $queryMap['signature']);
    }

    /**
     * Test case for getSummaryOfSubAccountsMarginAccount.
     *
     * Get Summary of Sub-account's Margin Account (For Master Account) (USER_DATA).
     */
    public function testGetSummaryOfSubAccountsMarginAccount()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSummaryOfSubAccountsMarginAccount($recvWindow);

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

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

    /**
     * Test case for marginTransferForSubAccount.
     *
     * Margin Transfer for Sub-account (For Master Account) (USER_DATA).
     */
    public function testMarginTransferForSubAccount()
    {
        $marginTransferForSubAccountRequest = new MarginTransferForSubAccountRequest();
        $marginTransferForSubAccountRequest->setEmail('sub-account-email@email.com');
        $marginTransferForSubAccountRequest->setAsset('');
        $marginTransferForSubAccountRequest->setAmount(1.0);
        $marginTransferForSubAccountRequest->setType(1);

        $response = $this->getApiMock($request)->marginTransferForSubAccount($marginTransferForSubAccountRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/sub-account/margin/transfer', $request->getUri()->getPath());
        self::assertEquals('b4be732ba42c0f53afd68a041c98176ce8a169c8c1e8257cfb8a64bc5f92cb90', $queryMap['signature']);
    }

    /**
     * Test case for movePositionForSubAccount.
     *
     * Move Position for Sub-account (For Master Account) (USER_DATA).
     */
    public function testMovePositionForSubAccount()
    {
        $movePositionForSubAccountRequest = new MovePositionForSubAccountRequest();
        $movePositionForSubAccountRequest->setFromUserEmail('');
        $movePositionForSubAccountRequest->setToUserEmail('');
        $movePositionForSubAccountRequest->setProductType('');
        $movePositionForSubAccountRequest->setOrderArgs(new OrderArgs());

        $response = $this->getApiMock($request)->movePositionForSubAccount($movePositionForSubAccountRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/sub-account/futures/move-position', $request->getUri()->getPath());
        self::assertEquals('53668e00dc92eb93de0b253c301e9fc0c20042b13db384a0ad94b38688a5a84c', $queryMap['signature']);
    }

    /**
     * Test case for querySubAccountAssets.
     *
     * Query Sub-account Assets (For Master Account) (USER_DATA).
     */
    public function testQuerySubAccountAssets()
    {
        $email = 'sub-account-email@email.com';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->querySubAccountAssets($email, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v3/sub-account/assets', $request->getUri()->getPath());
        self::assertEquals('bbb3a67207210f851b76211eae9566a7b03cd2d37dde4e5b73d48265f7b9197e', $queryMap['signature']);
    }

    /**
     * Test case for querySubAccountAssetsAssetManagement.
     *
     * Query Sub-account Assets (For Master Account) (USER_DATA).
     */
    public function testQuerySubAccountAssetsAssetManagement()
    {
        $email = 'sub-account-email@email.com';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->querySubAccountAssetsAssetManagement($email, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v4/sub-account/assets', $request->getUri()->getPath());
        self::assertEquals('bbb3a67207210f851b76211eae9566a7b03cd2d37dde4e5b73d48265f7b9197e', $queryMap['signature']);
    }

    /**
     * Test case for querySubAccountFuturesAssetTransferHistory.
     *
     * Query Sub-account Futures Asset Transfer History (For Master Account) (USER_DATA).
     */
    public function testQuerySubAccountFuturesAssetTransferHistory()
    {
        $email = 'sub-account-email@email.com';
        $futuresType = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $page = 1;
        $limit = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->querySubAccountFuturesAssetTransferHistory($email, $futuresType, $startTime, $endTime, $page, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/sub-account/futures/internalTransfer', $request->getUri()->getPath());
        self::assertEquals('ea4e6b7bf5e48b96c5100bc99293a3194f94197aeb291253f2c1430d2045f3c4', $queryMap['signature']);
    }

    /**
     * Test case for querySubAccountSpotAssetTransferHistory.
     *
     * Query Sub-account Spot Asset Transfer History (For Master Account) (USER_DATA).
     */
    public function testQuerySubAccountSpotAssetTransferHistory()
    {
        $fromEmail = '';
        $toEmail = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $page = 1;
        $limit = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->querySubAccountSpotAssetTransferHistory($fromEmail, $toEmail, $startTime, $endTime, $page, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/sub-account/sub/transfer/history', $request->getUri()->getPath());
        self::assertEquals('9ae9fd705409a66f2ebbd03bb81a1f1c4d0dadd4a45c6bd8e9080d6e40b6c078', $queryMap['signature']);
    }

    /**
     * Test case for querySubAccountSpotAssetsSummary.
     *
     * Query Sub-account Spot Assets Summary (For Master Account) (USER_DATA).
     */
    public function testQuerySubAccountSpotAssetsSummary()
    {
        $email = '';
        $page = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->querySubAccountSpotAssetsSummary($email, $page, $size, $recvWindow);

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

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

    /**
     * Test case for queryUniversalTransferHistory.
     *
     * Query Universal Transfer History (For Master Account) (USER_DATA).
     */
    public function testQueryUniversalTransferHistory()
    {
        $fromEmail = '';
        $toEmail = '';
        $clientTranId = '1';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $page = 1;
        $limit = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryUniversalTransferHistory($fromEmail, $toEmail, $clientTranId, $startTime, $endTime, $page, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/sub-account/universalTransfer', $request->getUri()->getPath());
        self::assertEquals('4e778b579ca592dd544e6c3652b16042473aad23cdbaf83554677253c7d95675', $queryMap['signature']);
    }

    /**
     * Test case for subAccountFuturesAssetTransfer.
     *
     * Sub-account Futures Asset Transfer (For Master Account) (USER_DATA).
     */
    public function testSubAccountFuturesAssetTransfer()
    {
        $subAccountFuturesAssetTransferRequest = new SubAccountFuturesAssetTransferRequest();
        $subAccountFuturesAssetTransferRequest->setFromEmail('');
        $subAccountFuturesAssetTransferRequest->setToEmail('');
        $subAccountFuturesAssetTransferRequest->setFuturesType(1);
        $subAccountFuturesAssetTransferRequest->setAsset('');
        $subAccountFuturesAssetTransferRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->subAccountFuturesAssetTransfer($subAccountFuturesAssetTransferRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/sub-account/futures/internalTransfer', $request->getUri()->getPath());
        self::assertEquals('405da57ce31ee6957bcd382e0646132c601fd9989425e373a122af445d4024d9', $queryMap['signature']);
    }

    /**
     * Test case for subAccountTransferHistory.
     *
     * Sub-account Transfer History (For Sub-account) (USER_DATA).
     */
    public function testSubAccountTransferHistory()
    {
        $asset = '';
        $type = null;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 1;
        $returnFailHistory = false;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->subAccountTransferHistory($asset, $type, $startTime, $endTime, $limit, $returnFailHistory, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/sub-account/transfer/subUserHistory', $request->getUri()->getPath());
        self::assertEquals('dfd25047950e40e3d1ec6461155e7a3e6abc5c3da582d9a524a9f37cdc3f658d', $queryMap['signature']);
    }

    /**
     * Test case for transferToMaster.
     *
     * Transfer to Master (For Sub-account) (USER_DATA).
     */
    public function testTransferToMaster()
    {
        $transferToMasterRequest = new TransferToMasterRequest();
        $transferToMasterRequest->setAsset('');
        $transferToMasterRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->transferToMaster($transferToMasterRequest);

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

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

    /**
     * Test case for transferToSubAccountOfSameMaster.
     *
     * Transfer to Sub-account of Same Master (For Sub-account) (USER_DATA).
     */
    public function testTransferToSubAccountOfSameMaster()
    {
        $transferToSubAccountOfSameMasterRequest = new TransferToSubAccountOfSameMasterRequest();
        $transferToSubAccountOfSameMasterRequest->setToEmail('');
        $transferToSubAccountOfSameMasterRequest->setAsset('');
        $transferToSubAccountOfSameMasterRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->transferToSubAccountOfSameMaster($transferToSubAccountOfSameMasterRequest);

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

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

    /**
     * Test case for universalTransfer.
     *
     * Universal Transfer (For Master Account) (USER_DATA).
     */
    public function testUniversalTransfer()
    {
        $universalTransferRequest = new UniversalTransferRequest();
        $universalTransferRequest->setFromAccountType('');
        $universalTransferRequest->setToAccountType('');
        $universalTransferRequest->setAsset('');
        $universalTransferRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->universalTransfer($universalTransferRequest);

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

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