<?php

/**
 * OnChainYieldsApiTest
 * 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\OnChainYieldsApi;
use Binance\Client\Staking\Model\RedeemOnChainYieldsLockedProductRequest;
use Binance\Client\Staking\Model\SetOnChainYieldsLockedAutoSubscribeRequest;
use Binance\Client\Staking\Model\SetOnChainYieldsLockedProductRedeemOptionRequest;
use Binance\Client\Staking\Model\SubscribeOnChainYieldsLockedProductRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for getOnChainYieldsLockedPersonalLeftQuota.
     *
     * Get On-chain Yields Locked Personal Left Quota (USER_DATA).
     */
    public function testGetOnChainYieldsLockedPersonalLeftQuota()
    {
        $projectId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOnChainYieldsLockedPersonalLeftQuota($projectId, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/personalLeftQuota', $request->getUri()->getPath());
        self::assertEquals('7df8536b8711da59322819086e27ee0e183d18d1f4d6a68377c9c4a87f835ab8', $queryMap['signature']);
    }

    /**
     * Test case for getOnChainYieldsLockedProductList.
     *
     * Get On-chain Yields Locked Product List (USER_DATA).
     */
    public function testGetOnChainYieldsLockedProductList()
    {
        $asset = '';
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOnChainYieldsLockedProductList($asset, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/list', $request->getUri()->getPath());
        self::assertEquals('bd638fc75eac7f4be7a462c128024f88315ab0149337f26f109b46f1202febbf', $queryMap['signature']);
    }

    /**
     * Test case for getOnChainYieldsLockedProductPosition.
     *
     * Get On-chain Yields Locked Product Position (USER_DATA).
     */
    public function testGetOnChainYieldsLockedProductPosition()
    {
        $asset = '';
        $positionId = '1';
        $projectId = '1';
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOnChainYieldsLockedProductPosition($asset, $positionId, $projectId, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/position', $request->getUri()->getPath());
        self::assertEquals('ccc89a5e48b80d17733b5836204753d96df9add461137f83d5c711197a36d9b1', $queryMap['signature']);
    }

    /**
     * Test case for getOnChainYieldsLockedRedemptionRecord.
     *
     * Get On-chain Yields Locked Redemption Record (USER_DATA).
     */
    public function testGetOnChainYieldsLockedRedemptionRecord()
    {
        $positionId = '1';
        $redeemId = '1';
        $asset = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOnChainYieldsLockedRedemptionRecord($positionId, $redeemId, $asset, $startTime, $endTime, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/history/redemptionRecord', $request->getUri()->getPath());
        self::assertEquals('8698c6aa7cbf81e6467758b6d887d6884b4a39502ef6a6bbd1a675de85cc86aa', $queryMap['signature']);
    }

    /**
     * Test case for getOnChainYieldsLockedRewardsHistory.
     *
     * Get On-chain Yields Locked Rewards History (USER_DATA).
     */
    public function testGetOnChainYieldsLockedRewardsHistory()
    {
        $positionId = '1';
        $asset = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOnChainYieldsLockedRewardsHistory($positionId, $asset, $startTime, $endTime, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/history/rewardsRecord', $request->getUri()->getPath());
        self::assertEquals('43f239a70e3fb817a2244ce73382c55891024b4882bc81598cea0c1cda4e172a', $queryMap['signature']);
    }

    /**
     * Test case for getOnChainYieldsLockedSubscriptionPreview.
     *
     * Get On-chain Yields Locked Subscription Preview (USER_DATA).
     */
    public function testGetOnChainYieldsLockedSubscriptionPreview()
    {
        $projectId = '1';
        $amount = 1.0;
        $autoSubscribe = false;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOnChainYieldsLockedSubscriptionPreview($projectId, $amount, $autoSubscribe, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/subscriptionPreview', $request->getUri()->getPath());
        self::assertEquals('ed6d60bbbd167523b7f2ff4be5baa4485dbf0f39322a1cb34907612d59aac34a', $queryMap['signature']);
    }

    /**
     * Test case for getOnChainYieldsLockedSubscriptionRecord.
     *
     * Get On-chain Yields Locked Subscription Record (USER_DATA).
     */
    public function testGetOnChainYieldsLockedSubscriptionRecord()
    {
        $purchaseId = '1';
        $clientId = '1';
        $asset = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOnChainYieldsLockedSubscriptionRecord($purchaseId, $clientId, $asset, $startTime, $endTime, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/history/subscriptionRecord', $request->getUri()->getPath());
        self::assertEquals('add467baaa6e50d6f65d0155211ef7772fceebc470c8d263f9771ef04a143656', $queryMap['signature']);
    }

    /**
     * Test case for onChainYieldsAccount.
     *
     * On-chain Yields Account (USER_DATA).
     */
    public function testOnChainYieldsAccount()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->onChainYieldsAccount($recvWindow);

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

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

    /**
     * Test case for redeemOnChainYieldsLockedProduct.
     *
     * Redeem On-chain Yields Locked Product (TRADE).
     */
    public function testRedeemOnChainYieldsLockedProduct()
    {
        $redeemOnChainYieldsLockedProductRequest = new RedeemOnChainYieldsLockedProductRequest();
        $redeemOnChainYieldsLockedProductRequest->setPositionId('1');

        $response = $this->getApiMock($request)->redeemOnChainYieldsLockedProduct($redeemOnChainYieldsLockedProductRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/redeem', $request->getUri()->getPath());
        self::assertEquals('05345189012e725ecf394a569c76b468c3a9d6377f5b644a1b90e1551920ce91', $queryMap['signature']);
    }

    /**
     * Test case for setOnChainYieldsLockedAutoSubscribe.
     *
     * Set On-chain Yields Locked Auto Subscribe(USER_DATA).
     */
    public function testSetOnChainYieldsLockedAutoSubscribe()
    {
        $setOnChainYieldsLockedAutoSubscribeRequest = new SetOnChainYieldsLockedAutoSubscribeRequest();
        $setOnChainYieldsLockedAutoSubscribeRequest->setPositionId('1');
        $setOnChainYieldsLockedAutoSubscribeRequest->setAutoSubscribe(false);

        $response = $this->getApiMock($request)->setOnChainYieldsLockedAutoSubscribe($setOnChainYieldsLockedAutoSubscribeRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/setAutoSubscribe', $request->getUri()->getPath());
        self::assertEquals('05345189012e725ecf394a569c76b468c3a9d6377f5b644a1b90e1551920ce91', $queryMap['signature']);
    }

    /**
     * Test case for setOnChainYieldsLockedProductRedeemOption.
     *
     * Set On-chain Yields Locked Product Redeem Option(USER_DATA).
     */
    public function testSetOnChainYieldsLockedProductRedeemOption()
    {
        $setOnChainYieldsLockedProductRedeemOptionRequest = new SetOnChainYieldsLockedProductRedeemOptionRequest();
        $setOnChainYieldsLockedProductRedeemOptionRequest->setPositionId('1');
        $setOnChainYieldsLockedProductRedeemOptionRequest->setRedeemTo('');

        $response = $this->getApiMock($request)->setOnChainYieldsLockedProductRedeemOption($setOnChainYieldsLockedProductRedeemOptionRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/setRedeemOption', $request->getUri()->getPath());
        self::assertEquals('05345189012e725ecf394a569c76b468c3a9d6377f5b644a1b90e1551920ce91', $queryMap['signature']);
    }

    /**
     * Test case for subscribeOnChainYieldsLockedProduct.
     *
     * Subscribe On-chain Yields Locked Product(TRADE).
     */
    public function testSubscribeOnChainYieldsLockedProduct()
    {
        $subscribeOnChainYieldsLockedProductRequest = new SubscribeOnChainYieldsLockedProductRequest();
        $subscribeOnChainYieldsLockedProductRequest->setProjectId('1');
        $subscribeOnChainYieldsLockedProductRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->subscribeOnChainYieldsLockedProduct($subscribeOnChainYieldsLockedProductRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/onchain-yields/locked/subscribe', $request->getUri()->getPath());
        self::assertEquals('7076688509283b4016a667a9fec02c11e72f52e87779a4cfe5085dad3dbedd37', $queryMap['signature']);
    }
}
