<?php

/**
 * HistoryApiTest
 * 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\HistoryApi;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for getCollateralRecord.
     *
     * Get Collateral Record(USER_DATA).
     */
    public function testGetCollateralRecord()
    {
        $productId = '1';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getCollateralRecord($productId, $startTime, $endTime, $current, $size, $recvWindow);

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

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

    /**
     * Test case for getFlexibleRedemptionRecord.
     *
     * Get Flexible Redemption Record(USER_DATA).
     */
    public function testGetFlexibleRedemptionRecord()
    {
        $productId = '1';
        $redeemId = '1';
        $asset = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleRedemptionRecord($productId, $redeemId, $asset, $startTime, $endTime, $current, $size, $recvWindow);

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

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

    /**
     * Test case for getFlexibleRewardsHistory.
     *
     * Get Flexible Rewards History(USER_DATA).
     */
    public function testGetFlexibleRewardsHistory()
    {
        $type = 'Bonus';
        $productId = '1';
        $asset = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleRewardsHistory($type, $productId, $asset, $startTime, $endTime, $current, $size, $recvWindow);

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

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

    /**
     * Test case for getFlexibleSubscriptionRecord.
     *
     * Get Flexible Subscription Record(USER_DATA).
     */
    public function testGetFlexibleSubscriptionRecord()
    {
        $productId = '1';
        $purchaseId = '1';
        $asset = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleSubscriptionRecord($productId, $purchaseId, $asset, $startTime, $endTime, $current, $size, $recvWindow);

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

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

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

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

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

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

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

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

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

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

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

    /**
     * Test case for getRateHistory.
     *
     * Get Rate History(USER_DATA).
     */
    public function testGetRateHistory()
    {
        $productId = '1';
        $aprPeriod = 'DAY';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getRateHistory($productId, $aprPeriod, $startTime, $endTime, $current, $size, $recvWindow);

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

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