<?php

/**
 * ManagedSubAccountApiTest
 * 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\ManagedSubAccountApi;
use Binance\Client\SubAccount\Model\DepositAssetsIntoTheManagedSubAccountRequest;
use Binance\Client\SubAccount\Model\WithdrawlAssetsFromTheManagedSubAccountRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for depositAssetsIntoTheManagedSubAccount.
     *
     * Deposit Assets Into The Managed Sub-account (For Investor Master Account) (USER_DATA).
     */
    public function testDepositAssetsIntoTheManagedSubAccount()
    {
        $depositAssetsIntoTheManagedSubAccountRequest = new DepositAssetsIntoTheManagedSubAccountRequest();
        $depositAssetsIntoTheManagedSubAccountRequest->setToEmail('');
        $depositAssetsIntoTheManagedSubAccountRequest->setAsset('');
        $depositAssetsIntoTheManagedSubAccountRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->depositAssetsIntoTheManagedSubAccount($depositAssetsIntoTheManagedSubAccountRequest);

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

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

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

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

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

    /**
     * Test case for queryManagedSubAccountAssetDetails.
     *
     * Query Managed Sub-account Asset Details (For Investor Master Account) (USER_DATA).
     */
    public function testQueryManagedSubAccountAssetDetails()
    {
        $email = 'sub-account-email@email.com';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryManagedSubAccountAssetDetails($email, $recvWindow);

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

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

    /**
     * Test case for queryManagedSubAccountFuturesAssetDetails.
     *
     * Query Managed Sub-account Futures Asset Details (For Investor Master Account) (USER_DATA).
     */
    public function testQueryManagedSubAccountFuturesAssetDetails()
    {
        $email = 'sub-account-email@email.com';
        $accountType = '';
        $response = $this->getApiMock($request)->queryManagedSubAccountFuturesAssetDetails($email, $accountType);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/managed-subaccount/fetch-future-asset', $request->getUri()->getPath());
        self::assertEquals('820b6569727150122d08dfff2abc0e35c35ceae85be364c1f99bb40352e460f3', $queryMap['signature']);
    }

    /**
     * Test case for queryManagedSubAccountList.
     *
     * Query Managed Sub-account List (For Investor) (USER_DATA).
     */
    public function testQueryManagedSubAccountList()
    {
        $email = '';
        $page = 1;
        $limit = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryManagedSubAccountList($email, $page, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/managed-subaccount/info', $request->getUri()->getPath());
        self::assertEquals('8a73086a1b7b0b8fdd097b5e9651c03b0a8938014f4aae424ed1db47d1030ab6', $queryMap['signature']);
    }

    /**
     * Test case for queryManagedSubAccountMarginAssetDetails.
     *
     * Query Managed Sub-account Margin Asset Details (For Investor Master Account) (USER_DATA).
     */
    public function testQueryManagedSubAccountMarginAssetDetails()
    {
        $email = 'sub-account-email@email.com';
        $accountType = '';
        $response = $this->getApiMock($request)->queryManagedSubAccountMarginAssetDetails($email, $accountType);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/managed-subaccount/marginAsset', $request->getUri()->getPath());
        self::assertEquals('820b6569727150122d08dfff2abc0e35c35ceae85be364c1f99bb40352e460f3', $queryMap['signature']);
    }

    /**
     * Test case for queryManagedSubAccountSnapshot.
     *
     * Query Managed Sub-account Snapshot (For Investor Master Account) (USER_DATA).
     */
    public function testQueryManagedSubAccountSnapshot()
    {
        $email = 'sub-account-email@email.com';
        $type = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryManagedSubAccountSnapshot($email, $type, $startTime, $endTime, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/managed-subaccount/accountSnapshot', $request->getUri()->getPath());
        self::assertEquals('798f63c636a19b23eafed70bc3b49d260b1a3c84da75aa5a05168e2c182eea14', $queryMap['signature']);
    }

    /**
     * Test case for queryManagedSubAccountTransferLogMasterAccountInvestor.
     *
     * Query Managed Sub Account Transfer Log (For Investor Master Account) (USER_DATA).
     */
    public function testQueryManagedSubAccountTransferLogMasterAccountInvestor()
    {
        $email = 'sub-account-email@email.com';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $page = 1;
        $limit = 10;
        $transfers = '';
        $transferFunctionAccountType = '';
        $response = $this->getApiMock($request)->queryManagedSubAccountTransferLogMasterAccountInvestor($email, $startTime, $endTime, $page, $limit, $transfers, $transferFunctionAccountType);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/managed-subaccount/queryTransLogForInvestor', $request->getUri()->getPath());
        self::assertEquals('52a09ba2cbc5e8cd67040dc1082194ad39fbe26e52fa1117fa3e114366a34220', $queryMap['signature']);
    }

    /**
     * Test case for queryManagedSubAccountTransferLogMasterAccountTrading.
     *
     * Query Managed Sub Account Transfer Log (For Trading Team Master Account) (USER_DATA).
     */
    public function testQueryManagedSubAccountTransferLogMasterAccountTrading()
    {
        $email = 'sub-account-email@email.com';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $page = 1;
        $limit = 10;
        $transfers = '';
        $transferFunctionAccountType = '';
        $response = $this->getApiMock($request)->queryManagedSubAccountTransferLogMasterAccountTrading($email, $startTime, $endTime, $page, $limit, $transfers, $transferFunctionAccountType);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/managed-subaccount/queryTransLogForTradeParent', $request->getUri()->getPath());
        self::assertEquals('52a09ba2cbc5e8cd67040dc1082194ad39fbe26e52fa1117fa3e114366a34220', $queryMap['signature']);
    }

    /**
     * Test case for queryManagedSubAccountTransferLogSubAccountTrading.
     *
     * Query Managed Sub Account Transfer Log (For Trading Team Sub Account) (USER_DATA).
     */
    public function testQueryManagedSubAccountTransferLogSubAccountTrading()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $page = 1;
        $limit = 10;
        $transfers = '';
        $transferFunctionAccountType = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryManagedSubAccountTransferLogSubAccountTrading($startTime, $endTime, $page, $limit, $transfers, $transferFunctionAccountType, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/managed-subaccount/query-trans-log', $request->getUri()->getPath());
        self::assertEquals('03bc40bac483566cc68e80dfe1a3184662800a723c8140ddbb212e9cf9a1bead', $queryMap['signature']);
    }

    /**
     * Test case for withdrawlAssetsFromTheManagedSubAccount.
     *
     * Withdrawl Assets From The Managed Sub-account (For Investor Master Account) (USER_DATA).
     */
    public function testWithdrawlAssetsFromTheManagedSubAccount()
    {
        $withdrawlAssetsFromTheManagedSubAccountRequest = new WithdrawlAssetsFromTheManagedSubAccountRequest();
        $withdrawlAssetsFromTheManagedSubAccountRequest->setFromEmail('');
        $withdrawlAssetsFromTheManagedSubAccountRequest->setAsset('');
        $withdrawlAssetsFromTheManagedSubAccountRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->withdrawlAssetsFromTheManagedSubAccount($withdrawlAssetsFromTheManagedSubAccountRequest);

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

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