<?php

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

/**
 * Binance Derivatives Trading USDS Futures REST API.
 *
 * OpenAPI Specification for the Binance Derivatives Trading USDS Futures 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\DerivativesTradingUsdsFutures\Test\Api;

use Binance\Client\DerivativesTradingUsdsFutures\Api\ConvertApi;
use Binance\Client\DerivativesTradingUsdsFutures\Model\AcceptTheOfferedQuoteRequest;
use Binance\Client\DerivativesTradingUsdsFutures\Model\SendQuoteRequestRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for acceptTheOfferedQuote.
     *
     * Accept the offered quote (USER_DATA).
     */
    public function testAcceptTheOfferedQuote()
    {
        $acceptTheOfferedQuoteRequest = new AcceptTheOfferedQuoteRequest();
        $acceptTheOfferedQuoteRequest->setQuoteId('1');

        $response = $this->getApiMock($request)->acceptTheOfferedQuote($acceptTheOfferedQuoteRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/fapi/v1/convert/acceptQuote', $request->getUri()->getPath());
        self::assertEquals('0624eea4af8a8321e2c84e368ed873d71a9a5c971e629175b93556bd22fc325d', $queryMap['signature']);
    }

    /**
     * Test case for listAllConvertPairs.
     *
     * List All Convert Pairs.
     */
    public function testListAllConvertPairs()
    {
        $fromAsset = '';
        $toAsset = '';
        $response = $this->getApiMock($request)->listAllConvertPairs($fromAsset, $toAsset);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/fapi/v1/convert/exchangeInfo', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for orderStatus.
     *
     * Order status(USER_DATA).
     */
    public function testOrderStatus()
    {
        $orderId = 1;
        $quoteId = '1';
        $response = $this->getApiMock($request)->orderStatus($orderId, $quoteId);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/fapi/v1/convert/orderStatus', $request->getUri()->getPath());
        self::assertEquals('c8ea02b290636497dfc9f4f59d01ea6ceff503bf1955b020615bd7bb133a81c4', $queryMap['signature']);
    }

    /**
     * Test case for sendQuoteRequest.
     *
     * Send Quote Request(USER_DATA).
     */
    public function testSendQuoteRequest()
    {
        $sendQuoteRequestRequest = new SendQuoteRequestRequest();
        $sendQuoteRequestRequest->setFromAsset('');
        $sendQuoteRequestRequest->setToAsset('');

        $response = $this->getApiMock($request)->sendQuoteRequest($sendQuoteRequestRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/fapi/v1/convert/getQuote', $request->getUri()->getPath());
        self::assertEquals('c2a41c5811da81c00258e452c20a96710858f159abce153ff6651b9a78b4490c', $queryMap['signature']);
    }
}
