<?php

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

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

use Binance\Client\DerivativesTradingOptions\Api\MarketMakerBlockTradeApi;
use Binance\Client\DerivativesTradingOptions\Model\AcceptBlockTradeOrderRequest;
use Binance\Client\DerivativesTradingOptions\Model\ExtendBlockTradeOrderRequest;
use Binance\Client\DerivativesTradingOptions\Model\Legs;
use Binance\Client\DerivativesTradingOptions\Model\NewBlockTradeOrderRequest;
use Binance\Client\DerivativesTradingOptions\Model\Side;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for acceptBlockTradeOrder.
     *
     * Accept Block Trade Order (TRADE).
     */
    public function testAcceptBlockTradeOrder()
    {
        $acceptBlockTradeOrderRequest = new AcceptBlockTradeOrderRequest();
        $acceptBlockTradeOrderRequest->setBlockOrderMatchingKey('');

        $response = $this->getApiMock($request)->acceptBlockTradeOrder($acceptBlockTradeOrderRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/block/order/execute', $request->getUri()->getPath());
        self::assertEquals('de380b325ca2fc542797817031f93ea098fb97e4c1890c11e6a786c934fd4c5a', $queryMap['signature']);
    }

    /**
     * Test case for accountBlockTradeList.
     *
     * Account Block Trade List (USER_DATA).
     */
    public function testAccountBlockTradeList()
    {
        $endTime = 1641782889000;
        $startTime = 1623319461670;
        $underlying = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->accountBlockTradeList($endTime, $startTime, $underlying, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/block/user-trades', $request->getUri()->getPath());
        self::assertEquals('04545a7dd0e70f8679487801f9aac979b2218eb30875a374939fe1525f75eec1', $queryMap['signature']);
    }

    /**
     * Test case for cancelBlockTradeOrder.
     *
     * Cancel Block Trade Order (TRADE).
     */
    public function testCancelBlockTradeOrder()
    {
        $blockOrderMatchingKey = '';
        $recvWindow = 5000;
        $this->getApiMock($request)->cancelBlockTradeOrder($blockOrderMatchingKey, $recvWindow);

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

        self::assertEquals('/eapi/v1/block/order/create', $request->getUri()->getPath());
        self::assertEquals('ae708c39578286d9f327c8abc95624dc3cc9d4999587112e264986264a52088a', $queryMap['signature']);
    }

    /**
     * Test case for extendBlockTradeOrder.
     *
     * Extend Block Trade Order (TRADE).
     */
    public function testExtendBlockTradeOrder()
    {
        $extendBlockTradeOrderRequest = new ExtendBlockTradeOrderRequest();
        $extendBlockTradeOrderRequest->setBlockOrderMatchingKey('');

        $response = $this->getApiMock($request)->extendBlockTradeOrder($extendBlockTradeOrderRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/block/order/create', $request->getUri()->getPath());
        self::assertEquals('de380b325ca2fc542797817031f93ea098fb97e4c1890c11e6a786c934fd4c5a', $queryMap['signature']);
    }

    /**
     * Test case for newBlockTradeOrder.
     *
     * New Block Trade Order (TRADE).
     */
    public function testNewBlockTradeOrder()
    {
        $newBlockTradeOrderRequest = new NewBlockTradeOrderRequest();
        $newBlockTradeOrderRequest->setLiquidity('');
        $newBlockTradeOrderRequest->setLegs(new Legs());
        $newBlockTradeOrderRequest->setSymbol('');
        $newBlockTradeOrderRequest->setSide(Side::BUY);
        $newBlockTradeOrderRequest->setPrice(1.0);
        $newBlockTradeOrderRequest->setQuantity(1.0);

        $response = $this->getApiMock($request)->newBlockTradeOrder($newBlockTradeOrderRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/block/order/create', $request->getUri()->getPath());
        self::assertEquals('d0491b0f4fd8117ca78b9f2e321ad83ddc8f25c9e4eab78fa6956499db004506', $queryMap['signature']);
    }

    /**
     * Test case for queryBlockTradeDetails.
     *
     * Query Block Trade Details (USER_DATA).
     */
    public function testQueryBlockTradeDetails()
    {
        $blockOrderMatchingKey = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryBlockTradeDetails($blockOrderMatchingKey, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/block/order/execute', $request->getUri()->getPath());
        self::assertEquals('ae708c39578286d9f327c8abc95624dc3cc9d4999587112e264986264a52088a', $queryMap['signature']);
    }

    /**
     * Test case for queryBlockTradeOrder.
     *
     * Query Block Trade Order (TRADE).
     */
    public function testQueryBlockTradeOrder()
    {
        $blockOrderMatchingKey = '';
        $endTime = 1641782889000;
        $startTime = 1623319461670;
        $underlying = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryBlockTradeOrder($blockOrderMatchingKey, $endTime, $startTime, $underlying, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/block/order/orders', $request->getUri()->getPath());
        self::assertEquals('04545a7dd0e70f8679487801f9aac979b2218eb30875a374939fe1525f75eec1', $queryMap['signature']);
    }
}
