<?php

/**
 * CapitalApiTest
 * 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\CapitalApi;
use Binance\Client\Wallet\Model\OneClickArrivalDepositApplyRequest;
use Binance\Client\Wallet\Model\WithdrawRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for allCoinsInformation.
     *
     * All Coins' Information (USER_DATA).
     */
    public function testAllCoinsInformation()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->allCoinsInformation($recvWindow);

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

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

    /**
     * Test case for depositAddress.
     *
     * Deposit Address(supporting network) (USER_DATA).
     */
    public function testDepositAddress()
    {
        $coin = '';
        $network = '';
        $amount = 1.0;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->depositAddress($coin, $network, $amount, $recvWindow);

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

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

    /**
     * Test case for depositHistory.
     *
     * Deposit History (supporting network) (USER_DATA).
     */
    public function testDepositHistory()
    {
        $includeSource = false;
        $coin = '';
        $status = null;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $offset = 0;
        $limit = 7;
        $recvWindow = 5000;
        $txId = '1';
        $response = $this->getApiMock($request)->depositHistory($includeSource, $coin, $status, $startTime, $endTime, $offset, $limit, $recvWindow, $txId);

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

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

    /**
     * Test case for fetchDepositAddressListWithNetwork.
     *
     * Fetch deposit address list with network(USER_DATA).
     */
    public function testFetchDepositAddressListWithNetwork()
    {
        $coin = '';
        $network = '';
        $response = $this->getApiMock($request)->fetchDepositAddressListWithNetwork($coin, $network);

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

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

    /**
     * Test case for fetchWithdrawAddressList.
     *
     * Fetch withdraw address list (USER_DATA).
     */
    public function testFetchWithdrawAddressList()
    {
        $response = $this->getApiMock($request)->fetchWithdrawAddressList();

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/capital/withdraw/address/list', $request->getUri()->getPath());
        self::assertEquals('53668e00dc92eb93de0b253c301e9fc0c20042b13db384a0ad94b38688a5a84c', $queryMap['signature']);
    }

    /**
     * Test case for fetchWithdrawQuota.
     *
     * Fetch withdraw quota (USER_DATA).
     */
    public function testFetchWithdrawQuota()
    {
        $response = $this->getApiMock($request)->fetchWithdrawQuota();

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/capital/withdraw/quota', $request->getUri()->getPath());
        self::assertEquals('53668e00dc92eb93de0b253c301e9fc0c20042b13db384a0ad94b38688a5a84c', $queryMap['signature']);
    }

    /**
     * Test case for oneClickArrivalDepositApply.
     *
     * One click arrival deposit apply (for expired address deposit) (USER_DATA).
     */
    public function testOneClickArrivalDepositApply()
    {
        $oneClickArrivalDepositApplyRequest = new OneClickArrivalDepositApplyRequest();

        $response = $this->getApiMock($request)->oneClickArrivalDepositApply($oneClickArrivalDepositApplyRequest);

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

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

    /**
     * Test case for withdraw.
     *
     * Withdraw(USER_DATA).
     */
    public function testWithdraw()
    {
        $withdrawRequest = new WithdrawRequest();
        $withdrawRequest->setCoin('');
        $withdrawRequest->setAddress('');
        $withdrawRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->withdraw($withdrawRequest);

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

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

    /**
     * Test case for withdrawHistory.
     *
     * Withdraw History (supporting network) (USER_DATA).
     */
    public function testWithdrawHistory()
    {
        $coin = '';
        $withdrawOrderId = '1';
        $status = null;
        $offset = 0;
        $limit = 7;
        $idList = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->withdrawHistory($coin, $withdrawOrderId, $status, $offset, $limit, $idList, $startTime, $endTime, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/capital/withdraw/history', $request->getUri()->getPath());
        self::assertEquals('99352aab7e16b4301cdb6e10a5fa4786fbde8ab6139358a6e5a10c00a990910d', $queryMap['signature']);
    }
}
