<?php

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

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

use Binance\Client\Staking\Api\EthStakingApi;
use Binance\Client\Staking\Model\RedeemEthRequest;
use Binance\Client\Staking\Model\SubscribeEthStakingRequest;
use Binance\Client\Staking\Model\WrapBethRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for ethStakingAccount.
     *
     * ETH Staking account(USER_DATA).
     */
    public function testEthStakingAccount()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->ethStakingAccount($recvWindow);

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

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

    /**
     * Test case for getCurrentEthStakingQuota.
     *
     * Get current ETH staking quota(USER_DATA).
     */
    public function testGetCurrentEthStakingQuota()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getCurrentEthStakingQuota($recvWindow);

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

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

    /**
     * Test case for getEthRedemptionHistory.
     *
     * Get ETH redemption history(USER_DATA).
     */
    public function testGetEthRedemptionHistory()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getEthRedemptionHistory($startTime, $endTime, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/eth-staking/eth/history/redemptionHistory', $request->getUri()->getPath());
        self::assertEquals('2ecc0415a3bdb2963e8030cdf6cf00de6f49d21b71ff939dda42e5756eb8ba66', $queryMap['signature']);
    }

    /**
     * Test case for getEthStakingHistory.
     *
     * Get ETH staking history(USER_DATA).
     */
    public function testGetEthStakingHistory()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getEthStakingHistory($startTime, $endTime, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/eth-staking/eth/history/stakingHistory', $request->getUri()->getPath());
        self::assertEquals('2ecc0415a3bdb2963e8030cdf6cf00de6f49d21b71ff939dda42e5756eb8ba66', $queryMap['signature']);
    }

    /**
     * Test case for getWbethRateHistory.
     *
     * Get WBETH Rate History(USER_DATA).
     */
    public function testGetWbethRateHistory()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getWbethRateHistory($startTime, $endTime, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/eth-staking/eth/history/rateHistory', $request->getUri()->getPath());
        self::assertEquals('2ecc0415a3bdb2963e8030cdf6cf00de6f49d21b71ff939dda42e5756eb8ba66', $queryMap['signature']);
    }

    /**
     * Test case for getWbethRewardsHistory.
     *
     * Get WBETH rewards history(USER_DATA).
     */
    public function testGetWbethRewardsHistory()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getWbethRewardsHistory($startTime, $endTime, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/eth-staking/eth/history/wbethRewardsHistory', $request->getUri()->getPath());
        self::assertEquals('2ecc0415a3bdb2963e8030cdf6cf00de6f49d21b71ff939dda42e5756eb8ba66', $queryMap['signature']);
    }

    /**
     * Test case for getWbethUnwrapHistory.
     *
     * Get WBETH unwrap history(USER_DATA).
     */
    public function testGetWbethUnwrapHistory()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getWbethUnwrapHistory($startTime, $endTime, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/eth-staking/wbeth/history/unwrapHistory', $request->getUri()->getPath());
        self::assertEquals('2ecc0415a3bdb2963e8030cdf6cf00de6f49d21b71ff939dda42e5756eb8ba66', $queryMap['signature']);
    }

    /**
     * Test case for getWbethWrapHistory.
     *
     * Get WBETH wrap history(USER_DATA).
     */
    public function testGetWbethWrapHistory()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getWbethWrapHistory($startTime, $endTime, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/eth-staking/wbeth/history/wrapHistory', $request->getUri()->getPath());
        self::assertEquals('2ecc0415a3bdb2963e8030cdf6cf00de6f49d21b71ff939dda42e5756eb8ba66', $queryMap['signature']);
    }

    /**
     * Test case for redeemEth.
     *
     * Redeem ETH(TRADE).
     */
    public function testRedeemEth()
    {
        $redeemEthRequest = new RedeemEthRequest();
        $redeemEthRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->redeemEth($redeemEthRequest);

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

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

    /**
     * Test case for subscribeEthStaking.
     *
     * Subscribe ETH Staking(TRADE).
     */
    public function testSubscribeEthStaking()
    {
        $subscribeEthStakingRequest = new SubscribeEthStakingRequest();
        $subscribeEthStakingRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->subscribeEthStaking($subscribeEthStakingRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/eth-staking/eth/stake', $request->getUri()->getPath());
        self::assertEquals('50d24733794b928836575c346769be26ee1fb5ffbf73f36933cd22c50116f74e', $queryMap['signature']);
    }

    /**
     * Test case for wrapBeth.
     *
     * Wrap BETH(TRADE).
     */
    public function testWrapBeth()
    {
        $wrapBethRequest = new WrapBethRequest();
        $wrapBethRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->wrapBeth($wrapBethRequest);

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

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