<?php

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

/**
 * Binance Margin Trading REST API.
 *
 * OpenAPI Specification for the Binance Margin Trading 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\MarginTrading\Test\Api;

use Binance\Client\MarginTrading\Api\AccountApi;
use Binance\Client\MarginTrading\Model\AdjustCrossMarginMaxLeverageRequest;
use Binance\Client\MarginTrading\Model\EnableIsolatedMarginAccountRequest;
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 adjustCrossMarginMaxLeverage.
     *
     * Adjust cross margin max leverage (USER_DATA).
     */
    public function testAdjustCrossMarginMaxLeverage()
    {
        $adjustCrossMarginMaxLeverageRequest = new AdjustCrossMarginMaxLeverageRequest();
        $adjustCrossMarginMaxLeverageRequest->setMaxLeverage(1);

        $response = $this->getApiMock($request)->adjustCrossMarginMaxLeverage($adjustCrossMarginMaxLeverageRequest);

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

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

    /**
     * Test case for disableIsolatedMarginAccount.
     *
     * Disable Isolated Margin Account (TRADE).
     */
    public function testDisableIsolatedMarginAccount()
    {
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->disableIsolatedMarginAccount($symbol, $recvWindow);

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

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

    /**
     * Test case for enableIsolatedMarginAccount.
     *
     * Enable Isolated Margin Account (TRADE).
     */
    public function testEnableIsolatedMarginAccount()
    {
        $enableIsolatedMarginAccountRequest = new EnableIsolatedMarginAccountRequest();
        $enableIsolatedMarginAccountRequest->setSymbol('');

        $response = $this->getApiMock($request)->enableIsolatedMarginAccount($enableIsolatedMarginAccountRequest);

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

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

    /**
     * Test case for getBnbBurnStatus.
     *
     * Get BNB Burn Status (USER_DATA).
     */
    public function testGetBnbBurnStatus()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getBnbBurnStatus($recvWindow);

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

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

    /**
     * Test case for getSummaryOfMarginAccount.
     *
     * Get Summary of Margin account (USER_DATA).
     */
    public function testGetSummaryOfMarginAccount()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSummaryOfMarginAccount($recvWindow);

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

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

    /**
     * Test case for queryCrossIsolatedMarginCapitalFlow.
     *
     * Query Cross Isolated Margin Capital Flow (USER_DATA).
     */
    public function testQueryCrossIsolatedMarginCapitalFlow()
    {
        $asset = '';
        $symbol = '';
        $type = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $fromId = 1;
        $limit = 500;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryCrossIsolatedMarginCapitalFlow($asset, $symbol, $type, $startTime, $endTime, $fromId, $limit, $recvWindow);

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

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

    /**
     * Test case for queryCrossMarginAccountDetails.
     *
     * Query Cross Margin Account Details (USER_DATA).
     */
    public function testQueryCrossMarginAccountDetails()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryCrossMarginAccountDetails($recvWindow);

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

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

    /**
     * Test case for queryCrossMarginFeeData.
     *
     * Query Cross Margin Fee Data (USER_DATA).
     */
    public function testQueryCrossMarginFeeData()
    {
        $vipLevel = 1;
        $coin = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryCrossMarginFeeData($vipLevel, $coin, $recvWindow);

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

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

    /**
     * Test case for queryEnabledIsolatedMarginAccountLimit.
     *
     * Query Enabled Isolated Margin Account Limit (USER_DATA).
     */
    public function testQueryEnabledIsolatedMarginAccountLimit()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryEnabledIsolatedMarginAccountLimit($recvWindow);

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

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

    /**
     * Test case for queryIsolatedMarginAccountInfo.
     *
     * Query Isolated Margin Account Info (USER_DATA).
     */
    public function testQueryIsolatedMarginAccountInfo()
    {
        $symbols = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryIsolatedMarginAccountInfo($symbols, $recvWindow);

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

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

    /**
     * Test case for queryIsolatedMarginFeeData.
     *
     * Query Isolated Margin Fee Data (USER_DATA).
     */
    public function testQueryIsolatedMarginFeeData()
    {
        $vipLevel = 1;
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryIsolatedMarginFeeData($vipLevel, $symbol, $recvWindow);

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

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