<?php

/**
 * MarketDataApiTest
 * 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\MarketDataApi;
use Binance\Client\DerivativesTradingCoinFutures\Model\ContractType;
use Binance\Client\DerivativesTradingCoinFutures\Model\Interval;
use Binance\Client\DerivativesTradingCoinFutures\Model\Period;
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 basis.
     *
     * Basis.
     */
    public function testBasis()
    {
        $pair = '';
        $contractType = ContractType::PERPETUAL;
        $period = Period::PERIOD_5M;
        $limit = 100;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $response = $this->getApiMock($request)->basis($pair, $contractType, $period, $limit, $startTime, $endTime);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/futures/data/basis', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for checkServerTime.
     *
     * Check Server time.
     */
    public function testCheckServerTime()
    {
        $response = $this->getApiMock($request)->checkServerTime();

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

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

    /**
     * Test case for compressedAggregateTradesList.
     *
     * Compressed/Aggregate Trades List.
     */
    public function testCompressedAggregateTradesList()
    {
        $symbol = '';
        $fromId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $response = $this->getApiMock($request)->compressedAggregateTradesList($symbol, $fromId, $startTime, $endTime, $limit);

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

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

    /**
     * Test case for continuousContractKlineCandlestickData.
     *
     * Continuous Contract Kline/Candlestick Data.
     */
    public function testContinuousContractKlineCandlestickData()
    {
        $pair = '';
        $contractType = ContractType::PERPETUAL;
        $interval = Interval::INTERVAL_1M;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $response = $this->getApiMock($request)->continuousContractKlineCandlestickData($pair, $contractType, $interval, $startTime, $endTime, $limit);

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

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

    /**
     * Test case for exchangeInformation.
     *
     * Exchange Information.
     */
    public function testExchangeInformation()
    {
        $response = $this->getApiMock($request)->exchangeInformation();

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

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

    /**
     * Test case for getFundingRateHistoryOfPerpetualFutures.
     *
     * Get Funding Rate History of Perpetual Futures.
     */
    public function testGetFundingRateHistoryOfPerpetualFutures()
    {
        $symbol = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $response = $this->getApiMock($request)->getFundingRateHistoryOfPerpetualFutures($symbol, $startTime, $endTime, $limit);

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

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

    /**
     * Test case for getFundingRateInfo.
     *
     * Get Funding Rate Info.
     */
    public function testGetFundingRateInfo()
    {
        $response = $this->getApiMock($request)->getFundingRateInfo();

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

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

    /**
     * Test case for indexPriceAndMarkPrice.
     *
     * Index Price and Mark Price.
     */
    public function testIndexPriceAndMarkPrice()
    {
        $symbol = '';
        $pair = '';
        $response = $this->getApiMock($request)->indexPriceAndMarkPrice($symbol, $pair);

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

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

    /**
     * Test case for indexPriceKlineCandlestickData.
     *
     * Index Price Kline/Candlestick Data.
     */
    public function testIndexPriceKlineCandlestickData()
    {
        $pair = '';
        $interval = Interval::INTERVAL_1M;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $response = $this->getApiMock($request)->indexPriceKlineCandlestickData($pair, $interval, $startTime, $endTime, $limit);

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

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

    /**
     * Test case for klineCandlestickData.
     *
     * Kline/Candlestick Data.
     */
    public function testKlineCandlestickData()
    {
        $symbol = '';
        $interval = Interval::INTERVAL_1M;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $response = $this->getApiMock($request)->klineCandlestickData($symbol, $interval, $startTime, $endTime, $limit);

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

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

    /**
     * Test case for longShortRatio.
     *
     * Long/Short Ratio.
     */
    public function testLongShortRatio()
    {
        $pair = '';
        $period = Period::PERIOD_5M;
        $limit = 100;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $response = $this->getApiMock($request)->longShortRatio($pair, $period, $limit, $startTime, $endTime);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/futures/data/globalLongShortAccountRatio', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for markPriceKlineCandlestickData.
     *
     * Mark Price Kline/Candlestick Data.
     */
    public function testMarkPriceKlineCandlestickData()
    {
        $symbol = '';
        $interval = Interval::INTERVAL_1M;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $response = $this->getApiMock($request)->markPriceKlineCandlestickData($symbol, $interval, $startTime, $endTime, $limit);

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

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

    /**
     * Test case for oldTradesLookup.
     *
     * Old Trades Lookup(MARKET_DATA).
     */
    public function testOldTradesLookup()
    {
        $symbol = '';
        $limit = 100;
        $fromId = 1;
        $response = $this->getApiMock($request)->oldTradesLookup($symbol, $limit, $fromId);

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

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

    /**
     * Test case for openInterest.
     *
     * Open Interest.
     */
    public function testOpenInterest()
    {
        $symbol = '';
        $response = $this->getApiMock($request)->openInterest($symbol);

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

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

    /**
     * Test case for openInterestStatistics.
     *
     * Open Interest Statistics.
     */
    public function testOpenInterestStatistics()
    {
        $pair = '';
        $contractType = ContractType::PERPETUAL;
        $period = Period::PERIOD_5M;
        $limit = 100;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $response = $this->getApiMock($request)->openInterestStatistics($pair, $contractType, $period, $limit, $startTime, $endTime);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/futures/data/openInterestHist', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for orderBook.
     *
     * Order Book.
     */
    public function testOrderBook()
    {
        $symbol = '';
        $limit = 100;
        $response = $this->getApiMock($request)->orderBook($symbol, $limit);

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

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

    /**
     * Test case for premiumIndexKlineData.
     *
     * Premium index Kline Data.
     */
    public function testPremiumIndexKlineData()
    {
        $symbol = '';
        $interval = Interval::INTERVAL_1M;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 100;
        $response = $this->getApiMock($request)->premiumIndexKlineData($symbol, $interval, $startTime, $endTime, $limit);

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

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

    /**
     * Test case for queryIndexPriceConstituents.
     *
     * Query Index Price Constituents.
     */
    public function testQueryIndexPriceConstituents()
    {
        $symbol = '';
        $response = $this->getApiMock($request)->queryIndexPriceConstituents($symbol);

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

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

    /**
     * Test case for recentTradesList.
     *
     * Recent Trades List.
     */
    public function testRecentTradesList()
    {
        $symbol = '';
        $limit = 100;
        $response = $this->getApiMock($request)->recentTradesList($symbol, $limit);

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

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

    /**
     * Test case for symbolOrderBookTicker.
     *
     * Symbol Order Book Ticker.
     */
    public function testSymbolOrderBookTicker()
    {
        $symbol = '';
        $pair = '';
        $response = $this->getApiMock($request)->symbolOrderBookTicker($symbol, $pair);

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

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

    /**
     * Test case for symbolPriceTicker.
     *
     * Symbol Price Ticker.
     */
    public function testSymbolPriceTicker()
    {
        $symbol = '';
        $pair = '';
        $response = $this->getApiMock($request)->symbolPriceTicker($symbol, $pair);

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

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

    /**
     * Test case for takerBuySellVolume.
     *
     * Taker Buy/Sell Volume.
     */
    public function testTakerBuySellVolume()
    {
        $pair = '';
        $contractType = ContractType::PERPETUAL;
        $period = Period::PERIOD_5M;
        $limit = 100;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $response = $this->getApiMock($request)->takerBuySellVolume($pair, $contractType, $period, $limit, $startTime, $endTime);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/futures/data/takerBuySellVol', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for testConnectivity.
     *
     * Test Connectivity.
     */
    public function testTestConnectivity()
    {
        $this->getApiMock($request)->testConnectivity();

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

        self::assertEquals('/dapi/v1/ping', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for ticker24hrPriceChangeStatistics.
     *
     * 24hr Ticker Price Change Statistics.
     */
    public function testTicker24hrPriceChangeStatistics()
    {
        $symbol = '';
        $pair = '';
        $response = $this->getApiMock($request)->ticker24hrPriceChangeStatistics($symbol, $pair);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/dapi/v1/ticker/24hr', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for topTraderLongShortRatioAccounts.
     *
     * Top Trader Long/Short Ratio (Accounts).
     */
    public function testTopTraderLongShortRatioAccounts()
    {
        $symbol = '';
        $period = Period::PERIOD_5M;
        $limit = 100;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $response = $this->getApiMock($request)->topTraderLongShortRatioAccounts($symbol, $period, $limit, $startTime, $endTime);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/futures/data/topLongShortAccountRatio', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for topTraderLongShortRatioPositions.
     *
     * Top Trader Long/Short Ratio (Positions).
     */
    public function testTopTraderLongShortRatioPositions()
    {
        $pair = '';
        $period = Period::PERIOD_5M;
        $limit = 100;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $response = $this->getApiMock($request)->topTraderLongShortRatioPositions($pair, $period, $limit, $startTime, $endTime);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/futures/data/topLongShortPositionRatio', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }
}
