<?php

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

/**
 * Binance Simple Earn REST API.
 *
 * OpenAPI Specification for the Binance Simple Earn 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\SimpleEarn\Test\Api;

use Binance\Client\SimpleEarn\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 getFlexiblePersonalLeftQuota.
     *
     * Get Flexible Personal Left Quota(USER_DATA).
     */
    public function testGetFlexiblePersonalLeftQuota()
    {
        $productId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexiblePersonalLeftQuota($productId, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/flexible/personalLeftQuota', $request->getUri()->getPath());
        self::assertEquals('3449171bcce7a8aa43ee9684da7eebf17feeecb24ed8fd2858ca78fcc5d87e85', $queryMap['signature']);
    }

    /**
     * Test case for getFlexibleProductPosition.
     *
     * Get Flexible Product Position(USER_DATA).
     */
    public function testGetFlexibleProductPosition()
    {
        $asset = '';
        $productId = '1';
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleProductPosition($asset, $productId, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/flexible/position', $request->getUri()->getPath());
        self::assertEquals('5d1a560b8fbc0cbd5441dd825bb0b128cc309f7300772dc63d502602e1b487db', $queryMap['signature']);
    }

    /**
     * Test case for getLockedPersonalLeftQuota.
     *
     * Get Locked Personal Left Quota(USER_DATA).
     */
    public function testGetLockedPersonalLeftQuota()
    {
        $projectId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getLockedPersonalLeftQuota($projectId, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/locked/personalLeftQuota', $request->getUri()->getPath());
        self::assertEquals('7df8536b8711da59322819086e27ee0e183d18d1f4d6a68377c9c4a87f835ab8', $queryMap['signature']);
    }

    /**
     * Test case for getLockedProductPosition.
     *
     * Get Locked Product Position.
     */
    public function testGetLockedProductPosition()
    {
        $asset = '';
        $positionId = '1';
        $projectId = '1';
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getLockedProductPosition($asset, $positionId, $projectId, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/locked/position', $request->getUri()->getPath());
        self::assertEquals('ccc89a5e48b80d17733b5836204753d96df9add461137f83d5c711197a36d9b1', $queryMap['signature']);
    }

    /**
     * Test case for getSimpleEarnFlexibleProductList.
     *
     * Get Simple Earn Flexible Product List(USER_DATA).
     */
    public function testGetSimpleEarnFlexibleProductList()
    {
        $asset = '';
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSimpleEarnFlexibleProductList($asset, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/flexible/list', $request->getUri()->getPath());
        self::assertEquals('bd638fc75eac7f4be7a462c128024f88315ab0149337f26f109b46f1202febbf', $queryMap['signature']);
    }

    /**
     * Test case for getSimpleEarnLockedProductList.
     *
     * Get Simple Earn Locked Product List(USER_DATA).
     */
    public function testGetSimpleEarnLockedProductList()
    {
        $asset = '';
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSimpleEarnLockedProductList($asset, $current, $size, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/simple-earn/locked/list', $request->getUri()->getPath());
        self::assertEquals('bd638fc75eac7f4be7a462c128024f88315ab0149337f26f109b46f1202febbf', $queryMap['signature']);
    }

    /**
     * Test case for simpleAccount.
     *
     * Simple Account(USER_DATA).
     */
    public function testSimpleAccount()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->simpleAccount($recvWindow);

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

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