<?php

/**
 * AccountApiTest
 * 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\AccountApi;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for accountCommission.
     *
     * Query Commission Rates.
     */
    public function testAccountCommission()
    {
        $symbol = 'BNBUSDT';
        $response = $this->getApiMock($request)->accountCommission($symbol);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/account/commission', $request->getUri()->getPath());
        self::assertEquals('0ffc690e548c601c0f1fac6208ae531f94448e66a4126acd33db21b4779d0f72', $queryMap['signature']);
    }

    /**
     * Test case for allOrderList.
     *
     * Query all Order lists.
     */
    public function testAllOrderList()
    {
        $fromId = 1;
        $startTime = 1735693200000;
        $endTime = 1735693200000;
        $limit = 500;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->allOrderList($fromId, $startTime, $endTime, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/allOrderList', $request->getUri()->getPath());
        self::assertEquals('3f96b521ab45f68dea5e3b363c355bdd37bc2834d4ec7457ac7990d2d75178c2', $queryMap['signature']);
    }

    /**
     * Test case for allOrders.
     *
     * All orders.
     */
    public function testAllOrders()
    {
        $symbol = 'BNBUSDT';
        $orderId = 1;
        $startTime = 1735693200000;
        $endTime = 1735693200000;
        $limit = 500;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->allOrders($symbol, $orderId, $startTime, $endTime, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/allOrders', $request->getUri()->getPath());
        self::assertEquals('7f857866c2bd2678db911c5a1084412d274ea5c0dca24c8cca5c97ba0bc38ea6', $queryMap['signature']);
    }

    /**
     * Test case for getAccount.
     *
     * Account information.
     */
    public function testGetAccount()
    {
        $omitZeroBalances = false;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getAccount($omitZeroBalances, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/account', $request->getUri()->getPath());
        self::assertEquals('80eb12d82de3d921dc6a83f98a28a092b813f6946f7ce7c57c0540c86607a60c', $queryMap['signature']);
    }

    /**
     * Test case for getOpenOrders.
     *
     * Current open orders.
     */
    public function testGetOpenOrders()
    {
        $symbol = 'BNBUSDT';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOpenOrders($symbol, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/openOrders', $request->getUri()->getPath());
        self::assertEquals('1c2ec70499498e5c5d2f4e98a7e24c74f2801642a8c3743d289dbfc1ca00c7a8', $queryMap['signature']);
    }

    /**
     * Test case for getOrder.
     *
     * Query order.
     */
    public function testGetOrder()
    {
        $symbol = 'BNBUSDT';
        $orderId = 1;
        $origClientOrderId = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOrder($symbol, $orderId, $origClientOrderId, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/order', $request->getUri()->getPath());
        self::assertEquals('7e08367f6bee9fed56adfad3dfd778f7654eb34d8c7769aacd85a02d1bb583f5', $queryMap['signature']);
    }

    /**
     * Test case for getOrderList.
     *
     * Query Order list.
     */
    public function testGetOrderList()
    {
        $orderListId = 1;
        $origClientOrderId = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getOrderList($orderListId, $origClientOrderId, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/orderList', $request->getUri()->getPath());
        self::assertEquals('4b9e67d788ff4bf8b7dfeed203190292abc17692538522593c6a51af10d137f8', $queryMap['signature']);
    }

    /**
     * Test case for myAllocations.
     *
     * Query Allocations.
     */
    public function testMyAllocations()
    {
        $symbol = 'BNBUSDT';
        $startTime = 1735693200000;
        $endTime = 1735693200000;
        $fromAllocationId = 1;
        $limit = 500;
        $orderId = 1;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->myAllocations($symbol, $startTime, $endTime, $fromAllocationId, $limit, $orderId, $recvWindow);

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

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

    /**
     * Test case for myPreventedMatches.
     *
     * Query Prevented Matches.
     */
    public function testMyPreventedMatches()
    {
        $symbol = 'BNBUSDT';
        $preventedMatchId = 1;
        $orderId = 1;
        $fromPreventedMatchId = 1;
        $limit = 500;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->myPreventedMatches($symbol, $preventedMatchId, $orderId, $fromPreventedMatchId, $limit, $recvWindow);

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

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

    /**
     * Test case for myTrades.
     *
     * Account trade list.
     */
    public function testMyTrades()
    {
        $symbol = 'BNBUSDT';
        $orderId = 1;
        $startTime = 1735693200000;
        $endTime = 1735693200000;
        $fromId = 1;
        $limit = 500;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->myTrades($symbol, $orderId, $startTime, $endTime, $fromId, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/myTrades', $request->getUri()->getPath());
        self::assertEquals('87114efcf71607d26ebed7c7ffab3ea9497a74121ac06151116831a22b8c8263', $queryMap['signature']);
    }

    /**
     * Test case for openOrderList.
     *
     * Query Open Order lists.
     */
    public function testOpenOrderList()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->openOrderList($recvWindow);

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

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

    /**
     * Test case for orderAmendments.
     *
     * Query Order Amendments.
     */
    public function testOrderAmendments()
    {
        $symbol = 'BNBUSDT';
        $orderId = 1;
        $fromExecutionId = 1;
        $limit = 500;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->orderAmendments($symbol, $orderId, $fromExecutionId, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/order/amendments', $request->getUri()->getPath());
        self::assertEquals('ca0d3131f6c797f1889c1e885ea1aebd286e8e3a673e5cf7719015123b2eb092', $queryMap['signature']);
    }

    /**
     * Test case for rateLimitOrder.
     *
     * Query Unfilled Order Count.
     */
    public function testRateLimitOrder()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->rateLimitOrder($recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/api/v3/rateLimit/order', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }
}
