<?php

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

/**
 * Binance Spot REST API.
 *
 * OpenAPI Specifications for the Binance Spot REST API  API documents:   - [Github rest-api documentation file](https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md)   - [General API information for rest-api on website](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-api-information)
 *
 * 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\Spot\Test\Api;

use Binance\Client\Spot\Api\MarketApi;
use Binance\Client\Spot\Model\Interval;
use Binance\Client\Spot\Model\TickerType;
use Binance\Client\Spot\Model\WindowSize;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for aggTrades.
     *
     * Compressed/Aggregate trades list.
     */
    public function testAggTrades()
    {
        $symbol = 'BNBUSDT';
        $fromId = 1;
        $startTime = 1735693200000;
        $endTime = 1735693200000;
        $limit = 500;
        $response = $this->getApiMock($request)->aggTrades($symbol, $fromId, $startTime, $endTime, $limit);

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

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

    /**
     * Test case for avgPrice.
     *
     * Current average price.
     */
    public function testAvgPrice()
    {
        $symbol = 'BNBUSDT';
        $response = $this->getApiMock($request)->avgPrice($symbol);

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

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

    /**
     * Test case for depth.
     *
     * Order book.
     */
    public function testDepth()
    {
        $symbol = 'BNBUSDT';
        $limit = 500;
        $response = $this->getApiMock($request)->depth($symbol, $limit);

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

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

    /**
     * Test case for getTrades.
     *
     * Recent trades list.
     */
    public function testGetTrades()
    {
        $symbol = 'BNBUSDT';
        $limit = 500;
        $response = $this->getApiMock($request)->getTrades($symbol, $limit);

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

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

    /**
     * Test case for historicalTrades.
     *
     * Old trade lookup.
     */
    public function testHistoricalTrades()
    {
        $symbol = 'BNBUSDT';
        $limit = 500;
        $fromId = 1;
        $response = $this->getApiMock($request)->historicalTrades($symbol, $limit, $fromId);

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

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

    /**
     * Test case for klines.
     *
     * Kline/Candlestick data.
     */
    public function testKlines()
    {
        $symbol = 'BNBUSDT';
        $interval = Interval::INTERVAL_1S;
        $startTime = 1735693200000;
        $endTime = 1735693200000;
        $timeZone = '';
        $limit = 500;
        $response = $this->getApiMock($request)->klines($symbol, $interval, $startTime, $endTime, $timeZone, $limit);

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

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

    /**
     * Test case for ticker.
     *
     * Rolling window price change statistics.
     */
    public function testTicker()
    {
        $symbol = 'BNBUSDT';
        $symbols = null;
        $windowSize = WindowSize::WINDOW_SIZE_1M;
        $type = TickerType::FULL;
        $response = $this->getApiMock($request)->ticker($symbol, $symbols, $windowSize, $type);

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

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

    /**
     * Test case for ticker24hr.
     *
     * 24hr ticker price change statistics.
     */
    public function testTicker24hr()
    {
        $symbol = 'BNBUSDT';
        $symbols = null;
        $type = TickerType::FULL;
        $response = $this->getApiMock($request)->ticker24hr($symbol, $symbols, $type);

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

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

    /**
     * Test case for tickerBookTicker.
     *
     * Symbol order book ticker.
     */
    public function testTickerBookTicker()
    {
        $symbol = 'BNBUSDT';
        $symbols = null;
        $response = $this->getApiMock($request)->tickerBookTicker($symbol, $symbols);

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

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

    /**
     * Test case for tickerPrice.
     *
     * Symbol price ticker.
     */
    public function testTickerPrice()
    {
        $symbol = 'BNBUSDT';
        $symbols = null;
        $response = $this->getApiMock($request)->tickerPrice($symbol, $symbols);

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

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

    /**
     * Test case for tickerTradingDay.
     *
     * Trading Day Ticker.
     */
    public function testTickerTradingDay()
    {
        $symbol = 'BNBUSDT';
        $symbols = null;
        $timeZone = '';
        $type = TickerType::FULL;
        $response = $this->getApiMock($request)->tickerTradingDay($symbol, $symbols, $timeZone, $type);

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

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

    /**
     * Test case for uiKlines.
     *
     * UIKlines.
     */
    public function testUiKlines()
    {
        $symbol = 'BNBUSDT';
        $interval = Interval::INTERVAL_1S;
        $startTime = 1735693200000;
        $endTime = 1735693200000;
        $timeZone = '';
        $limit = 500;
        $response = $this->getApiMock($request)->uiKlines($symbol, $interval, $startTime, $endTime, $timeZone, $limit);

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

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