<?php

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

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

use Binance\Client\Wallet\Api\AssetApi;
use Binance\Client\Wallet\Model\DustTransferRequest;
use Binance\Client\Wallet\Model\FundingWalletRequest;
use Binance\Client\Wallet\Model\GetAssetsThatCanBeConvertedIntoBnbRequest;
use Binance\Client\Wallet\Model\ToggleBnbBurnOnSpotTradeAndMarginInterestRequest;
use Binance\Client\Wallet\Model\UserAssetRequest;
use Binance\Client\Wallet\Model\UserUniversalTransferRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for assetDetail.
     *
     * Asset Detail (USER_DATA).
     */
    public function testAssetDetail()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->assetDetail($recvWindow);

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

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

    /**
     * Test case for assetDividendRecord.
     *
     * Asset Dividend Record (USER_DATA).
     */
    public function testAssetDividendRecord()
    {
        $asset = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 7;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->assetDividendRecord($asset, $startTime, $endTime, $limit, $recvWindow);

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

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

    /**
     * Test case for dustTransfer.
     *
     * Dust Transfer (USER_DATA).
     */
    public function testDustTransfer()
    {
        $dustTransferRequest = new DustTransferRequest();
        $dustTransferRequest->setAsset('');

        $response = $this->getApiMock($request)->dustTransfer($dustTransferRequest);

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

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

    /**
     * Test case for dustlog.
     *
     * DustLog(USER_DATA).
     */
    public function testDustlog()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->dustlog($startTime, $endTime, $recvWindow);

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

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

    /**
     * Test case for fundingWallet.
     *
     * Funding Wallet (USER_DATA).
     */
    public function testFundingWallet()
    {
        $fundingWalletRequest = new FundingWalletRequest();

        $response = $this->getApiMock($request)->fundingWallet($fundingWalletRequest);

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

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

    /**
     * Test case for getAssetsThatCanBeConvertedIntoBnb.
     *
     * Get Assets That Can Be Converted Into BNB (USER_DATA).
     */
    public function testGetAssetsThatCanBeConvertedIntoBnb()
    {
        $getAssetsThatCanBeConvertedIntoBnbRequest = new GetAssetsThatCanBeConvertedIntoBnbRequest();

        $response = $this->getApiMock($request)->getAssetsThatCanBeConvertedIntoBnb($getAssetsThatCanBeConvertedIntoBnbRequest);

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

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

    /**
     * Test case for getCloudMiningPaymentAndRefundHistory.
     *
     * Get Cloud-Mining payment and refund history (USER_DATA).
     */
    public function testGetCloudMiningPaymentAndRefundHistory()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $tranId = 1;
        $clientTranId = '1';
        $asset = '';
        $current = 1;
        $size = 10;
        $response = $this->getApiMock($request)->getCloudMiningPaymentAndRefundHistory($startTime, $endTime, $tranId, $clientTranId, $asset, $current, $size);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage', $request->getUri()->getPath());
        self::assertEquals('fc5861c679752b9e41eee8e49b11fd6ca99aa2892d159ba5d29e915692d09431', $queryMap['signature']);
    }

    /**
     * Test case for getOpenSymbolList.
     *
     * Get Open Symbol List (MARKET_DATA).
     */
    public function testGetOpenSymbolList()
    {
        $response = $this->getApiMock($request)->getOpenSymbolList();

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/spot/open-symbol-list', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for queryUserDelegationHistory.
     *
     * Query User Delegation History(For Master Account)(USER_DATA).
     */
    public function testQueryUserDelegationHistory()
    {
        $email = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $type = '';
        $asset = '';
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryUserDelegationHistory($email, $startTime, $endTime, $type, $asset, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/asset/custody/transfer-history', $request->getUri()->getPath());
        self::assertEquals('902f3aebafab582a601c675c4db18bec806fdd4dfff7467bc5ccd4d9891d7d59', $queryMap['signature']);
    }

    /**
     * Test case for queryUserUniversalTransferHistory.
     *
     * Query User Universal Transfer History(USER_DATA).
     */
    public function testQueryUserUniversalTransferHistory()
    {
        $type = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $fromSymbol = '';
        $toSymbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryUserUniversalTransferHistory($type, $startTime, $endTime, $current, $size, $fromSymbol, $toSymbol, $recvWindow);

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

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

    /**
     * Test case for queryUserWalletBalance.
     *
     * Query User Wallet Balance (USER_DATA).
     */
    public function testQueryUserWalletBalance()
    {
        $quoteAsset = 'BTC';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryUserWalletBalance($quoteAsset, $recvWindow);

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

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

    /**
     * Test case for toggleBnbBurnOnSpotTradeAndMarginInterest.
     *
     * Toggle BNB Burn On Spot Trade And Margin Interest (USER_DATA).
     */
    public function testToggleBnbBurnOnSpotTradeAndMarginInterest()
    {
        $toggleBnbBurnOnSpotTradeAndMarginInterestRequest = new ToggleBnbBurnOnSpotTradeAndMarginInterestRequest();

        $response = $this->getApiMock($request)->toggleBnbBurnOnSpotTradeAndMarginInterest($toggleBnbBurnOnSpotTradeAndMarginInterestRequest);

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

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

    /**
     * Test case for tradeFee.
     *
     * Trade Fee (USER_DATA).
     */
    public function testTradeFee()
    {
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->tradeFee($symbol, $recvWindow);

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

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

    /**
     * Test case for userAsset.
     *
     * User Asset (USER_DATA).
     */
    public function testUserAsset()
    {
        $userAssetRequest = new UserAssetRequest();

        $response = $this->getApiMock($request)->userAsset($userAssetRequest);

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

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

    /**
     * Test case for userUniversalTransfer.
     *
     * User Universal Transfer (USER_DATA).
     */
    public function testUserUniversalTransfer()
    {
        $userUniversalTransferRequest = new UserUniversalTransferRequest();
        $userUniversalTransferRequest->setType('');
        $userUniversalTransferRequest->setAsset('');
        $userUniversalTransferRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->userUniversalTransfer($userUniversalTransferRequest);

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

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