<?php

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

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

use Binance\Client\SimpleEarn\Api\EarnApi;
use Binance\Client\SimpleEarn\Model\RedeemFlexibleProductRequest;
use Binance\Client\SimpleEarn\Model\RedeemLockedProductRequest;
use Binance\Client\SimpleEarn\Model\SetFlexibleAutoSubscribeRequest;
use Binance\Client\SimpleEarn\Model\SetLockedAutoSubscribeRequest;
use Binance\Client\SimpleEarn\Model\SetLockedProductRedeemOptionRequest;
use Binance\Client\SimpleEarn\Model\SubscribeFlexibleProductRequest;
use Binance\Client\SimpleEarn\Model\SubscribeLockedProductRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for getFlexibleSubscriptionPreview.
     *
     * Get Flexible Subscription Preview(USER_DATA).
     */
    public function testGetFlexibleSubscriptionPreview()
    {
        $productId = '1';
        $amount = 1.0;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleSubscriptionPreview($productId, $amount, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/flexible/subscriptionPreview', $request->getUri()->getPath());
        self::assertEquals('00a7c80c0c410b10c6a3067e01f82fc810a365b87c83c5086e7224f826896ff5', $queryMap['signature']);
    }

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

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

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

    /**
     * Test case for redeemFlexibleProduct.
     *
     * Redeem Flexible Product(TRADE).
     */
    public function testRedeemFlexibleProduct()
    {
        $redeemFlexibleProductRequest = new RedeemFlexibleProductRequest();
        $redeemFlexibleProductRequest->setProductId('1');

        $response = $this->getApiMock($request)->redeemFlexibleProduct($redeemFlexibleProductRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/flexible/redeem', $request->getUri()->getPath());
        self::assertEquals('c4c7af86a6a8cfafc9909bb0dec0f67695e17aba2a88ca75e983de6e0b915279', $queryMap['signature']);
    }

    /**
     * Test case for redeemLockedProduct.
     *
     * Redeem Locked Product(TRADE).
     */
    public function testRedeemLockedProduct()
    {
        $redeemLockedProductRequest = new RedeemLockedProductRequest();
        $redeemLockedProductRequest->setPositionId('1');

        $response = $this->getApiMock($request)->redeemLockedProduct($redeemLockedProductRequest);

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

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

    /**
     * Test case for setFlexibleAutoSubscribe.
     *
     * Set Flexible Auto Subscribe(USER_DATA).
     */
    public function testSetFlexibleAutoSubscribe()
    {
        $setFlexibleAutoSubscribeRequest = new SetFlexibleAutoSubscribeRequest();
        $setFlexibleAutoSubscribeRequest->setProductId('1');
        $setFlexibleAutoSubscribeRequest->setAutoSubscribe(false);

        $response = $this->getApiMock($request)->setFlexibleAutoSubscribe($setFlexibleAutoSubscribeRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/flexible/setAutoSubscribe', $request->getUri()->getPath());
        self::assertEquals('c4c7af86a6a8cfafc9909bb0dec0f67695e17aba2a88ca75e983de6e0b915279', $queryMap['signature']);
    }

    /**
     * Test case for setLockedAutoSubscribe.
     *
     * Set Locked Auto Subscribe(USER_DATA).
     */
    public function testSetLockedAutoSubscribe()
    {
        $setLockedAutoSubscribeRequest = new SetLockedAutoSubscribeRequest();
        $setLockedAutoSubscribeRequest->setPositionId('1');
        $setLockedAutoSubscribeRequest->setAutoSubscribe(false);

        $response = $this->getApiMock($request)->setLockedAutoSubscribe($setLockedAutoSubscribeRequest);

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

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

    /**
     * Test case for setLockedProductRedeemOption.
     *
     * Set Locked Product Redeem Option(USER_DATA).
     */
    public function testSetLockedProductRedeemOption()
    {
        $setLockedProductRedeemOptionRequest = new SetLockedProductRedeemOptionRequest();
        $setLockedProductRedeemOptionRequest->setPositionId('1');
        $setLockedProductRedeemOptionRequest->setRedeemTo('');

        $response = $this->getApiMock($request)->setLockedProductRedeemOption($setLockedProductRedeemOptionRequest);

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

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

    /**
     * Test case for subscribeFlexibleProduct.
     *
     * Subscribe Flexible Product(TRADE).
     */
    public function testSubscribeFlexibleProduct()
    {
        $subscribeFlexibleProductRequest = new SubscribeFlexibleProductRequest();
        $subscribeFlexibleProductRequest->setProductId('1');
        $subscribeFlexibleProductRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->subscribeFlexibleProduct($subscribeFlexibleProductRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/flexible/subscribe', $request->getUri()->getPath());
        self::assertEquals('3dee22bd6696da63a05dcfeab0e3354c811f0ccee9225496640c2d08bd9e234d', $queryMap['signature']);
    }

    /**
     * Test case for subscribeLockedProduct.
     *
     * Subscribe Locked Product(TRADE).
     */
    public function testSubscribeLockedProduct()
    {
        $subscribeLockedProductRequest = new SubscribeLockedProductRequest();
        $subscribeLockedProductRequest->setProjectId('1');
        $subscribeLockedProductRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->subscribeLockedProduct($subscribeLockedProductRequest);

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

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