<?php

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

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

use Binance\Client\GiftCard\Api\MarketDataApi;
use Binance\Client\GiftCard\Model\CreateADualTokenGiftCardRequest;
use Binance\Client\GiftCard\Model\CreateASingleTokenGiftCardRequest;
use Binance\Client\GiftCard\Model\RedeemABinanceGiftCardRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for createADualTokenGiftCard.
     *
     * Create a dual-token gift card(fixed value, discount feature)(TRADE).
     */
    public function testCreateADualTokenGiftCard()
    {
        $createADualTokenGiftCardRequest = new CreateADualTokenGiftCardRequest();
        $createADualTokenGiftCardRequest->setBaseToken('');
        $createADualTokenGiftCardRequest->setFaceToken('');
        $createADualTokenGiftCardRequest->setBaseTokenAmount(1.0);

        $response = $this->getApiMock($request)->createADualTokenGiftCard($createADualTokenGiftCardRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/giftcard/buyCode', $request->getUri()->getPath());
        self::assertEquals('d697c4693bbce864cdc658fdec9b9f954cd9be159dad7a269a56d208f5859d1f', $queryMap['signature']);
    }

    /**
     * Test case for createASingleTokenGiftCard.
     *
     * Create a single-token gift card (USER_DATA).
     */
    public function testCreateASingleTokenGiftCard()
    {
        $createASingleTokenGiftCardRequest = new CreateASingleTokenGiftCardRequest();
        $createASingleTokenGiftCardRequest->setToken('');
        $createASingleTokenGiftCardRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->createASingleTokenGiftCard($createASingleTokenGiftCardRequest);

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

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

    /**
     * Test case for fetchRsaPublicKey.
     *
     * Fetch RSA Public Key(USER_DATA).
     */
    public function testFetchRsaPublicKey()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->fetchRsaPublicKey($recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/giftcard/cryptography/rsa-public-key', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for fetchTokenLimit.
     *
     * Fetch Token Limit(USER_DATA).
     */
    public function testFetchTokenLimit()
    {
        $baseToken = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->fetchTokenLimit($baseToken, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/giftcard/buyCode/token-limit', $request->getUri()->getPath());
        self::assertEquals('ad48ec2424bc86ad21d7fc07d5661584031423f7843df207b496c96683f24adf', $queryMap['signature']);
    }

    /**
     * Test case for redeemABinanceGiftCard.
     *
     * Redeem a Binance Gift Card(USER_DATA).
     */
    public function testRedeemABinanceGiftCard()
    {
        $redeemABinanceGiftCardRequest = new RedeemABinanceGiftCardRequest();
        $redeemABinanceGiftCardRequest->setCode('');

        $response = $this->getApiMock($request)->redeemABinanceGiftCard($redeemABinanceGiftCardRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/giftcard/redeemCode', $request->getUri()->getPath());
        self::assertEquals('1ba360d97529c2640c7636928169e7b722b2aff893571bf4d7fd5c22be5d2523', $queryMap['signature']);
    }

    /**
     * Test case for verifyBinanceGiftCardByGiftCardNumber.
     *
     * Verify Binance Gift Card by Gift Card Number(USER_DATA).
     */
    public function testVerifyBinanceGiftCardByGiftCardNumber()
    {
        $referenceNo = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->verifyBinanceGiftCardByGiftCardNumber($referenceNo, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/giftcard/verify', $request->getUri()->getPath());
        self::assertEquals('bf4fdc473e45ef2efce7f171ab61a231969e9924b1a839b72500868675378a6f', $queryMap['signature']);
    }
}
