<?php

/**
 * TradeApiTest
 * 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\TradeApi;
use Binance\Client\DerivativesTradingOptions\Model\NewOrderRequest;
use Binance\Client\DerivativesTradingOptions\Model\Orders;
use Binance\Client\DerivativesTradingOptions\Model\PlaceMultipleOrdersRequest;
use Binance\Client\DerivativesTradingOptions\Model\Side;
use Binance\Client\DerivativesTradingOptions\Model\Type;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for accountTradeList.
     *
     * Account Trade List (USER_DATA).
     */
    public function testAccountTradeList()
    {
        $symbol = '';
        $fromId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->accountTradeList($symbol, $fromId, $startTime, $endTime, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/userTrades', $request->getUri()->getPath());
        self::assertEquals('61b488868ac713a73a80bc2a2702ed4b195aeb136137d09a8678e33a99f2d71d', $queryMap['signature']);
    }

    /**
     * Test case for cancelAllOptionOrdersByUnderlying.
     *
     * Cancel All Option Orders By Underlying (TRADE).
     */
    public function testCancelAllOptionOrdersByUnderlying()
    {
        $underlying = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->cancelAllOptionOrdersByUnderlying($underlying, $recvWindow);

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

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

    /**
     * Test case for cancelAllOptionOrdersOnSpecificSymbol.
     *
     * Cancel all Option orders on specific symbol (TRADE).
     */
    public function testCancelAllOptionOrdersOnSpecificSymbol()
    {
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->cancelAllOptionOrdersOnSpecificSymbol($symbol, $recvWindow);

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

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

    /**
     * Test case for cancelMultipleOptionOrders.
     *
     * Cancel Multiple Option Orders (TRADE).
     */
    public function testCancelMultipleOptionOrders()
    {
        $symbol = '';
        $orderIds = null;
        $clientOrderIds = null;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->cancelMultipleOptionOrders($symbol, $orderIds, $clientOrderIds, $recvWindow);

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

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

    /**
     * Test case for cancelOptionOrder.
     *
     * Cancel Option Order (TRADE).
     */
    public function testCancelOptionOrder()
    {
        $symbol = '';
        $orderId = 1;
        $clientOrderId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->cancelOptionOrder($symbol, $orderId, $clientOrderId, $recvWindow);

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

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

    /**
     * Test case for newOrder.
     *
     * New Order (TRADE).
     */
    public function testNewOrder()
    {
        $newOrderRequest = new NewOrderRequest();
        $newOrderRequest->setSymbol('');
        $newOrderRequest->setSide(Side::BUY);
        $newOrderRequest->setType(Type::LIMIT);
        $newOrderRequest->setQuantity(1.0);

        $response = $this->getApiMock($request)->newOrder($newOrderRequest);

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

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

    /**
     * Test case for optionPositionInformation.
     *
     * Option Position Information (USER_DATA).
     */
    public function testOptionPositionInformation()
    {
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->optionPositionInformation($symbol, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/position', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for placeMultipleOrders.
     *
     * Place Multiple Orders(TRADE).
     */
    public function testPlaceMultipleOrders()
    {
        $placeMultipleOrdersRequest = new PlaceMultipleOrdersRequest();
        $placeMultipleOrdersRequest->setOrders(new Orders());

        $response = $this->getApiMock($request)->placeMultipleOrders($placeMultipleOrdersRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/batchOrders', $request->getUri()->getPath());
        self::assertEquals('53668e00dc92eb93de0b253c301e9fc0c20042b13db384a0ad94b38688a5a84c', $queryMap['signature']);
    }

    /**
     * Test case for queryCurrentOpenOptionOrders.
     *
     * Query Current Open Option Orders (USER_DATA).
     */
    public function testQueryCurrentOpenOptionOrders()
    {
        $symbol = '';
        $orderId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryCurrentOpenOptionOrders($symbol, $orderId, $startTime, $endTime, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/openOrders', $request->getUri()->getPath());
        self::assertEquals('55af0bd73b4d687e474ef8be964b80431b1dc08d9d4927c2e6c815a79bca3d5a', $queryMap['signature']);
    }

    /**
     * Test case for queryOptionOrderHistory.
     *
     * Query Option Order History (TRADE).
     */
    public function testQueryOptionOrderHistory()
    {
        $symbol = '';
        $orderId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryOptionOrderHistory($symbol, $orderId, $startTime, $endTime, $limit, $recvWindow);

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

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

    /**
     * Test case for querySingleOrder.
     *
     * Query Single Order (TRADE).
     */
    public function testQuerySingleOrder()
    {
        $symbol = '';
        $orderId = 1;
        $clientOrderId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->querySingleOrder($symbol, $orderId, $clientOrderId, $recvWindow);

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

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

    /**
     * Test case for userExerciseRecord.
     *
     * User Exercise Record (USER_DATA).
     */
    public function testUserExerciseRecord()
    {
        $symbol = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->userExerciseRecord($symbol, $startTime, $endTime, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/eapi/v1/exerciseRecord', $request->getUri()->getPath());
        self::assertEquals('23689f3330f331d9db9c46c9dc87d2217486442f1746adfdda02c10e3dbde13e', $queryMap['signature']);
    }
}
