<?php

/**
 * AccountManagementApiTest
 * 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\AccountManagementApi;
use Binance\Client\SubAccount\Model\CreateAVirtualSubAccountRequest;
use Binance\Client\SubAccount\Model\EnableFuturesForSubAccountRequest;
use Binance\Client\SubAccount\Model\EnableOptionsForSubAccountRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for createAVirtualSubAccount.
     *
     * Create a Virtual Sub-account (For Master Account) (USER_DATA).
     */
    public function testCreateAVirtualSubAccount()
    {
        $createAVirtualSubAccountRequest = new CreateAVirtualSubAccountRequest();
        $createAVirtualSubAccountRequest->setSubAccountString('');

        $response = $this->getApiMock($request)->createAVirtualSubAccount($createAVirtualSubAccountRequest);

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

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

    /**
     * Test case for enableFuturesForSubAccount.
     *
     * Enable Futures for Sub-account (For Master Account) (USER_DATA).
     */
    public function testEnableFuturesForSubAccount()
    {
        $enableFuturesForSubAccountRequest = new EnableFuturesForSubAccountRequest();
        $enableFuturesForSubAccountRequest->setEmail('sub-account-email@email.com');

        $response = $this->getApiMock($request)->enableFuturesForSubAccount($enableFuturesForSubAccountRequest);

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

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

    /**
     * Test case for enableOptionsForSubAccount.
     *
     * Enable Options for Sub-account (For Master Account) (USER_DATA).
     */
    public function testEnableOptionsForSubAccount()
    {
        $enableOptionsForSubAccountRequest = new EnableOptionsForSubAccountRequest();
        $enableOptionsForSubAccountRequest->setEmail('sub-account-email@email.com');

        $response = $this->getApiMock($request)->enableOptionsForSubAccount($enableOptionsForSubAccountRequest);

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

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

    /**
     * Test case for getFuturesPositionRiskOfSubAccount.
     *
     * Get Futures Position-Risk of Sub-account (For Master Account) (USER_DATA).
     */
    public function testGetFuturesPositionRiskOfSubAccount()
    {
        $email = 'sub-account-email@email.com';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFuturesPositionRiskOfSubAccount($email, $recvWindow);

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

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

    /**
     * Test case for getFuturesPositionRiskOfSubAccountV2.
     *
     * Get Futures Position-Risk of Sub-account V2 (For Master Account) (USER_DATA).
     */
    public function testGetFuturesPositionRiskOfSubAccountV2()
    {
        $email = 'sub-account-email@email.com';
        $futuresType = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFuturesPositionRiskOfSubAccountV2($email, $futuresType, $recvWindow);

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

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

    /**
     * Test case for getSubAccountsStatusOnMarginOrFutures.
     *
     * Get Sub-account's Status on Margin Or Futures (For Master Account) (USER_DATA).
     */
    public function testGetSubAccountsStatusOnMarginOrFutures()
    {
        $email = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSubAccountsStatusOnMarginOrFutures($email, $recvWindow);

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

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

    /**
     * Test case for querySubAccountList.
     *
     * Query Sub-account List (For Master Account) (USER_DATA).
     */
    public function testQuerySubAccountList()
    {
        $email = '';
        $isFreeze = '';
        $page = 1;
        $limit = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->querySubAccountList($email, $isFreeze, $page, $limit, $recvWindow);

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

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

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

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

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