<?php

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

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

use Binance\Client\DerivativesTradingCoinFutures\Api\TradeApi;
use Binance\Client\DerivativesTradingCoinFutures\Model\AutoCancelAllOpenOrdersRequest;
use Binance\Client\DerivativesTradingCoinFutures\Model\AutoCloseType;
use Binance\Client\DerivativesTradingCoinFutures\Model\BatchOrders;
use Binance\Client\DerivativesTradingCoinFutures\Model\ChangeInitialLeverageRequest;
use Binance\Client\DerivativesTradingCoinFutures\Model\ChangeMarginTypeRequest;
use Binance\Client\DerivativesTradingCoinFutures\Model\ChangePositionModeRequest;
use Binance\Client\DerivativesTradingCoinFutures\Model\MarginType;
use Binance\Client\DerivativesTradingCoinFutures\Model\ModifyIsolatedPositionMarginRequest;
use Binance\Client\DerivativesTradingCoinFutures\Model\ModifyMultipleOrdersRequest;
use Binance\Client\DerivativesTradingCoinFutures\Model\ModifyOrderRequest;
use Binance\Client\DerivativesTradingCoinFutures\Model\NewOrderRequest;
use Binance\Client\DerivativesTradingCoinFutures\Model\Side;
use Binance\Client\DerivativesTradingCoinFutures\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 = '';
        $pair = '';
        $orderId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $fromId = 1;
        $limit = 100;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->accountTradeList($symbol, $pair, $orderId, $startTime, $endTime, $fromId, $limit, $recvWindow);

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

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

    /**
     * Test case for allOrders.
     *
     * All Orders (USER_DATA).
     */
    public function testAllOrders()
    {
        $symbol = '';
        $pair = '';
        $orderId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->allOrders($symbol, $pair, $orderId, $startTime, $endTime, $limit, $recvWindow);

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

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

    /**
     * Test case for autoCancelAllOpenOrders.
     *
     * Auto-Cancel All Open Orders (TRADE).
     */
    public function testAutoCancelAllOpenOrders()
    {
        $autoCancelAllOpenOrdersRequest = new AutoCancelAllOpenOrdersRequest();
        $autoCancelAllOpenOrdersRequest->setSymbol('');
        $autoCancelAllOpenOrdersRequest->setCountdownTime(100);

        $this->getApiMock($request)->autoCancelAllOpenOrders($autoCancelAllOpenOrdersRequest);

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

        self::assertEquals('/dapi/v1/countdownCancelAll', $request->getUri()->getPath());
        self::assertEquals('2a6a8357653f444de03f2fa97dd19a78b1b6459ce33a8cba863c08cc2228110d', $queryMap['signature']);
    }

    /**
     * Test case for cancelAllOpenOrders.
     *
     * Cancel All Open Orders(TRADE).
     */
    public function testCancelAllOpenOrders()
    {
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->cancelAllOpenOrders($symbol, $recvWindow);

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

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

    /**
     * Test case for cancelMultipleOrders.
     *
     * Cancel Multiple Orders(TRADE).
     */
    public function testCancelMultipleOrders()
    {
        $symbol = '';
        $orderIdList = null;
        $origClientOrderIdList = null;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->cancelMultipleOrders($symbol, $orderIdList, $origClientOrderIdList, $recvWindow);

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

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

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

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

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

    /**
     * Test case for changeInitialLeverage.
     *
     * Change Initial Leverage (TRADE).
     */
    public function testChangeInitialLeverage()
    {
        $changeInitialLeverageRequest = new ChangeInitialLeverageRequest();
        $changeInitialLeverageRequest->setSymbol('');
        $changeInitialLeverageRequest->setLeverage(1);

        $response = $this->getApiMock($request)->changeInitialLeverage($changeInitialLeverageRequest);

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

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

    /**
     * Test case for changeMarginType.
     *
     * Change Margin Type (TRADE).
     */
    public function testChangeMarginType()
    {
        $changeMarginTypeRequest = new ChangeMarginTypeRequest();
        $changeMarginTypeRequest->setSymbol('');
        $changeMarginTypeRequest->setMarginType(MarginType::ISOLATED);

        $response = $this->getApiMock($request)->changeMarginType($changeMarginTypeRequest);

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

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

    /**
     * Test case for changePositionMode.
     *
     * Change Position Mode(TRADE).
     */
    public function testChangePositionMode()
    {
        $changePositionModeRequest = new ChangePositionModeRequest();
        $changePositionModeRequest->setDualSidePosition('');

        $response = $this->getApiMock($request)->changePositionMode($changePositionModeRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/dapi/v1/positionSide/dual', $request->getUri()->getPath());
        self::assertEquals('bebef105cea3efc7f04654c618d2083229fcfc36b20173f0634e17be5042abd9', $queryMap['signature']);
    }

    /**
     * Test case for currentAllOpenOrders.
     *
     * Current All Open Orders (USER_DATA).
     */
    public function testCurrentAllOpenOrders()
    {
        $symbol = '';
        $pair = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->currentAllOpenOrders($symbol, $pair, $recvWindow);

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

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

    /**
     * Test case for getOrderModifyHistory.
     *
     * Get Order Modify History (USER_DATA).
     */
    public function testGetOrderModifyHistory()
    {
        $symbol = '';
        $orderId = 1;
        $origClientOrderId = '1';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOrderModifyHistory($symbol, $orderId, $origClientOrderId, $startTime, $endTime, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/dapi/v1/orderAmendment', $request->getUri()->getPath());
        self::assertEquals('8dfcc843fc05f631a3b12c4a0080f9d1f2283472ee0032b3e7e7fd46d855bcde', $queryMap['signature']);
    }

    /**
     * Test case for getPositionMarginChangeHistory.
     *
     * Get Position Margin Change History(TRADE).
     */
    public function testGetPositionMarginChangeHistory()
    {
        $symbol = '';
        $type = Type::LIMIT;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getPositionMarginChangeHistory($symbol, $type, $startTime, $endTime, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/dapi/v1/positionMargin/history', $request->getUri()->getPath());
        self::assertEquals('28df29b15a98006243407bf3bf886a72f9747c27314862a75b89f0916e58f097', $queryMap['signature']);
    }

    /**
     * Test case for modifyIsolatedPositionMargin.
     *
     * Modify Isolated Position Margin(TRADE).
     */
    public function testModifyIsolatedPositionMargin()
    {
        $modifyIsolatedPositionMarginRequest = new ModifyIsolatedPositionMarginRequest();
        $modifyIsolatedPositionMarginRequest->setSymbol('');
        $modifyIsolatedPositionMarginRequest->setAmount(1.0);
        $modifyIsolatedPositionMarginRequest->setType(Type::LIMIT);

        $response = $this->getApiMock($request)->modifyIsolatedPositionMargin($modifyIsolatedPositionMarginRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/dapi/v1/positionMargin', $request->getUri()->getPath());
        self::assertEquals('64f3ec596be04f63732d3edcec1351ff688c31ea96c407021d10862aeb2a68db', $queryMap['signature']);
    }

    /**
     * Test case for modifyMultipleOrders.
     *
     * Modify Multiple Orders(TRADE).
     */
    public function testModifyMultipleOrders()
    {
        $modifyMultipleOrdersRequest = new ModifyMultipleOrdersRequest();
        $modifyMultipleOrdersRequest->setBatchOrders(new BatchOrders());

        $response = $this->getApiMock($request)->modifyMultipleOrders($modifyMultipleOrdersRequest);

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

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

    /**
     * Test case for modifyOrder.
     *
     * Modify Order (TRADE).
     */
    public function testModifyOrder()
    {
        $modifyOrderRequest = new ModifyOrderRequest();
        $modifyOrderRequest->setSymbol('');
        $modifyOrderRequest->setSide(Side::BUY);

        $response = $this->getApiMock($request)->modifyOrder($modifyOrderRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/dapi/v1/order', $request->getUri()->getPath());
        self::assertEquals('2cb0badbb7aa9dcc202c9eb7a490346d9b1444ead428cc697587340c4ffefff0', $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);

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

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

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

    /**
     * Test case for positionAdlQuantileEstimation.
     *
     * Position ADL Quantile Estimation(USER_DATA).
     */
    public function testPositionAdlQuantileEstimation()
    {
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->positionAdlQuantileEstimation($symbol, $recvWindow);

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

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

    /**
     * Test case for positionInformation.
     *
     * Position Information(USER_DATA).
     */
    public function testPositionInformation()
    {
        $marginAsset = '';
        $pair = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->positionInformation($marginAsset, $pair, $recvWindow);

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

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

    /**
     * Test case for queryCurrentOpenOrder.
     *
     * Query Current Open Order(USER_DATA).
     */
    public function testQueryCurrentOpenOrder()
    {
        $symbol = '';
        $orderId = 1;
        $origClientOrderId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryCurrentOpenOrder($symbol, $orderId, $origClientOrderId, $recvWindow);

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

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

    /**
     * Test case for queryOrder.
     *
     * Query Order (USER_DATA).
     */
    public function testQueryOrder()
    {
        $symbol = '';
        $orderId = 1;
        $origClientOrderId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryOrder($symbol, $orderId, $origClientOrderId, $recvWindow);

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

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

    /**
     * Test case for usersForceOrders.
     *
     * User's Force Orders(USER_DATA).
     */
    public function testUsersForceOrders()
    {
        $symbol = '';
        $autoCloseType = AutoCloseType::LIQUIDATION;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->usersForceOrders($symbol, $autoCloseType, $startTime, $endTime, $limit, $recvWindow);

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

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