<?php

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

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

use Binance\Client\Mining\Api\MiningApi;
use Binance\Client\Mining\Configuration;
use Binance\Client\Mining\Model\CancelHashrateResaleConfigurationRequest;
use Binance\Client\Mining\Model\HashrateResaleRequestRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for accountList.
     *
     * Account List(USER_DATA).
     */
    public function testAccountList()
    {
        $algo = '';
        $userName = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->accountList($algo, $userName, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/mining/statistics/user/list', $request->getUri()->getPath());
        self::assertEquals('141af9d2d84660e9e442d9499a0db96fbe222cb8547ee7ab7e98858f8246dd7a', $queryMap['signature']);
    }

    /**
     * Test case for acquiringAlgorithm.
     *
     * Acquiring Algorithm(MARKET_DATA).
     */
    public function testAcquiringAlgorithm()
    {
        $response = $this->getApiMock($request)->acquiringAlgorithm();

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

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

    /**
     * Test case for acquiringCoinname.
     *
     * Acquiring CoinName(MARKET_DATA).
     */
    public function testAcquiringCoinname()
    {
        $response = $this->getApiMock($request)->acquiringCoinname();

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

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

    /**
     * Test case for cancelHashrateResaleConfiguration.
     *
     * Cancel hashrate resale configuration(USER_DATA).
     */
    public function testCancelHashrateResaleConfiguration()
    {
        $cancelHashrateResaleConfigurationRequest = new CancelHashrateResaleConfigurationRequest();
        $cancelHashrateResaleConfigurationRequest->setConfigId(1);
        $cancelHashrateResaleConfigurationRequest->setUserName('');

        $response = $this->getApiMock($request)->cancelHashrateResaleConfiguration($cancelHashrateResaleConfigurationRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/mining/hash-transfer/config/cancel', $request->getUri()->getPath());
        self::assertEquals('f8ceb73c814fab0ba66260335159fd26db4919ccf503612c817903e27a07b349', $queryMap['signature']);
    }

    /**
     * Test case for earningsList.
     *
     * Earnings List(USER_DATA).
     */
    public function testEarningsList()
    {
        $algo = '';
        $userName = '';
        $coin = '';
        $startDate = null;
        $endDate = null;
        $pageIndex = 1;
        $pageSize = null;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->earningsList($algo, $userName, $coin, $startDate, $endDate, $pageIndex, $pageSize, $recvWindow);

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

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

    /**
     * Test case for extraBonusList.
     *
     * Extra Bonus List(USER_DATA).
     */
    public function testExtraBonusList()
    {
        $algo = '';
        $userName = '';
        $coin = '';
        $startDate = null;
        $endDate = null;
        $pageIndex = 1;
        $pageSize = null;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->extraBonusList($algo, $userName, $coin, $startDate, $endDate, $pageIndex, $pageSize, $recvWindow);

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

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

    /**
     * Test case for hashrateResaleDetail.
     *
     * Hashrate Resale Detail(USER_DATA).
     */
    public function testHashrateResaleDetail()
    {
        $configId = 1;
        $userName = '';
        $pageIndex = 1;
        $pageSize = null;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->hashrateResaleDetail($configId, $userName, $pageIndex, $pageSize, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/mining/hash-transfer/profit/details', $request->getUri()->getPath());
        self::assertEquals('0e8fcfdcf386327eada1fb1bb00c69111c8c7d861aaa5def89182a273784e2ae', $queryMap['signature']);
    }

    /**
     * Test case for hashrateResaleList.
     *
     * Hashrate Resale List.
     */
    public function testHashrateResaleList()
    {
        $pageIndex = 1;
        $pageSize = null;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->hashrateResaleList($pageIndex, $pageSize, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/mining/hash-transfer/config/details/list', $request->getUri()->getPath());
        self::assertEquals('ce6d79e8ca1c93301887a7adbf692dbf52428b0523c5689069f37a586fa8e037', $queryMap['signature']);
    }

    /**
     * Test case for hashrateResaleRequest.
     *
     * Hashrate Resale Request(USER_DATA).
     */
    public function testHashrateResaleRequest()
    {
        $hashrateResaleRequestRequest = new HashrateResaleRequestRequest();
        $hashrateResaleRequestRequest->setUserName('');
        $hashrateResaleRequestRequest->setAlgo('');
        $hashrateResaleRequestRequest->setEndDate(1);
        $hashrateResaleRequestRequest->setStartDate(1);
        $hashrateResaleRequestRequest->setToPoolUser('');
        $hashrateResaleRequestRequest->setHashRate(1);

        $response = $this->getApiMock($request)->hashrateResaleRequest($hashrateResaleRequestRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/mining/hash-transfer/config', $request->getUri()->getPath());
        self::assertEquals('6e06e4ca2c97b5bdd66fad401431abd9d29b17b7fbeadd69f70008d522d56679', $queryMap['signature']);
    }

    /**
     * Test case for miningAccountEarning.
     *
     * Mining Account Earning(USER_DATA).
     */
    public function testMiningAccountEarning()
    {
        $algo = '';
        $startDate = null;
        $endDate = null;
        $pageIndex = 1;
        $pageSize = null;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->miningAccountEarning($algo, $startDate, $endDate, $pageIndex, $pageSize, $recvWindow);

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

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

    /**
     * Test case for requestForDetailMinerList.
     *
     * Request for Detail Miner List(USER_DATA).
     */
    public function testRequestForDetailMinerList()
    {
        $algo = '';
        $userName = '';
        $workerName = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->requestForDetailMinerList($algo, $userName, $workerName, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/mining/worker/detail', $request->getUri()->getPath());
        self::assertEquals('18fd7f75b1cdf1312e37d06b70439a0ac45a1ce7dfa5325eb634192ab2126af5', $queryMap['signature']);
    }

    /**
     * Test case for requestForMinerList.
     *
     * Request for Miner List(USER_DATA).
     */
    public function testRequestForMinerList()
    {
        $algo = '';
        $userName = '';
        $pageIndex = 1;
        $sort = 0;
        $sortColumn = 1;
        $workerStatus = 0;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->requestForMinerList($algo, $userName, $pageIndex, $sort, $sortColumn, $workerStatus, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/mining/worker/list', $request->getUri()->getPath());
        self::assertEquals('71a9590cb1f71643402b6f00af8944be65056eeebcad9c6cdefa09cd44b514b4', $queryMap['signature']);
    }

    /**
     * Test case for statisticList.
     *
     * Statistic List(USER_DATA).
     */
    public function testStatisticList()
    {
        $algo = '';
        $userName = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->statisticList($algo, $userName, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/mining/statistics/user/status', $request->getUri()->getPath());
        self::assertEquals('141af9d2d84660e9e442d9499a0db96fbe222cb8547ee7ab7e98858f8246dd7a', $queryMap['signature']);
    }
}
