<?php

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

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

use Binance\Client\MarginTrading\Api\MarketDataApi;
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 crossMarginCollateralRatio.
     *
     * Cross margin collateral ratio (MARKET_DATA).
     */
    public function testCrossMarginCollateralRatio()
    {
        $response = $this->getApiMock($request)->crossMarginCollateralRatio();

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

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

    /**
     * Test case for getAllCrossMarginPairs.
     *
     * Get All Cross Margin Pairs (MARKET_DATA).
     */
    public function testGetAllCrossMarginPairs()
    {
        $symbol = '';
        $response = $this->getApiMock($request)->getAllCrossMarginPairs($symbol);

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

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

    /**
     * Test case for getAllIsolatedMarginSymbol.
     *
     * Get All Isolated Margin Symbol(MARKET_DATA).
     */
    public function testGetAllIsolatedMarginSymbol()
    {
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getAllIsolatedMarginSymbol($symbol, $recvWindow);

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

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

    /**
     * Test case for getAllMarginAssets.
     *
     * Get All Margin Assets (MARKET_DATA).
     */
    public function testGetAllMarginAssets()
    {
        $asset = '';
        $response = $this->getApiMock($request)->getAllMarginAssets($asset);

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

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

    /**
     * Test case for getDelistSchedule.
     *
     * Get Delist Schedule (MARKET_DATA).
     */
    public function testGetDelistSchedule()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getDelistSchedule($recvWindow);

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

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

    /**
     * Test case for getListSchedule.
     *
     * Get list Schedule (MARKET_DATA).
     */
    public function testGetListSchedule()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getListSchedule($recvWindow);

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

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

    /**
     * Test case for queryIsolatedMarginTierData.
     *
     * Query Isolated Margin Tier Data (USER_DATA).
     */
    public function testQueryIsolatedMarginTierData()
    {
        $symbol = '';
        $tier = null;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryIsolatedMarginTierData($symbol, $tier, $recvWindow);

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

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

    /**
     * Test case for queryLiabilityCoinLeverageBracketInCrossMarginProMode.
     *
     * Query Liability Coin Leverage Bracket in Cross Margin Pro Mode(MARKET_DATA).
     */
    public function testQueryLiabilityCoinLeverageBracketInCrossMarginProMode()
    {
        $response = $this->getApiMock($request)->queryLiabilityCoinLeverageBracketInCrossMarginProMode();

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

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

    /**
     * Test case for queryMarginAvailableInventory.
     *
     * Query Margin Available Inventory(USER_DATA).
     */
    public function testQueryMarginAvailableInventory()
    {
        $type = '';
        $response = $this->getApiMock($request)->queryMarginAvailableInventory($type);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/available-inventory', $request->getUri()->getPath());
        self::assertEquals('a0a00da616718f873c1bc76aa304e6124894ea2b3df857101576732dca4e8f53', $queryMap['signature']);
    }

    /**
     * Test case for queryMarginPriceindex.
     *
     * Query Margin PriceIndex (MARKET_DATA).
     */
    public function testQueryMarginPriceindex()
    {
        $symbol = '';
        $response = $this->getApiMock($request)->queryMarginPriceindex($symbol);

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

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