<?php

/**
 * BorrowRepayApiTest
 * 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\BorrowRepayApi;
use Binance\Client\MarginTrading\Model\MarginAccountBorrowRepayRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for getFutureHourlyInterestRate.
     *
     * Get future hourly interest rate (USER_DATA).
     */
    public function testGetFutureHourlyInterestRate()
    {
        $assets = '';
        $isIsolated = 'false';
        $response = $this->getApiMock($request)->getFutureHourlyInterestRate($assets, $isIsolated);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/next-hourly-interest-rate', $request->getUri()->getPath());
        self::assertEquals('2387652ad7bac3e1193d741e641740cf64adb884868d4a1e300d99a49a15ea31', $queryMap['signature']);
    }

    /**
     * Test case for getInterestHistory.
     *
     * Get Interest History (USER_DATA).
     */
    public function testGetInterestHistory()
    {
        $asset = '';
        $isolatedSymbol = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getInterestHistory($asset, $isolatedSymbol, $startTime, $endTime, $current, $size, $recvWindow);

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

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

    /**
     * Test case for marginAccountBorrowRepay.
     *
     * Margin account borrow/repay(MARGIN).
     */
    public function testMarginAccountBorrowRepay()
    {
        $marginAccountBorrowRepayRequest = new MarginAccountBorrowRepayRequest();
        $marginAccountBorrowRepayRequest->setAsset('');
        $marginAccountBorrowRepayRequest->setIsIsolated('false');
        $marginAccountBorrowRepayRequest->setSymbol('');
        $marginAccountBorrowRepayRequest->setAmount('');
        $marginAccountBorrowRepayRequest->setType('');

        $response = $this->getApiMock($request)->marginAccountBorrowRepay($marginAccountBorrowRepayRequest);

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

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

    /**
     * Test case for queryBorrowRepayRecordsInMarginAccount.
     *
     * Query borrow/repay records in Margin account(USER_DATA).
     */
    public function testQueryBorrowRepayRecordsInMarginAccount()
    {
        $type = '';
        $asset = '';
        $isolatedSymbol = '';
        $txId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryBorrowRepayRecordsInMarginAccount($type, $asset, $isolatedSymbol, $txId, $startTime, $endTime, $current, $size, $recvWindow);

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

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

    /**
     * Test case for queryMarginInterestRateHistory.
     *
     * Query Margin Interest Rate History (USER_DATA).
     */
    public function testQueryMarginInterestRateHistory()
    {
        $asset = '';
        $vipLevel = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryMarginInterestRateHistory($asset, $vipLevel, $startTime, $endTime, $recvWindow);

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

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

    /**
     * Test case for queryMaxBorrow.
     *
     * Query Max Borrow (USER_DATA).
     */
    public function testQueryMaxBorrow()
    {
        $asset = '';
        $isolatedSymbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryMaxBorrow($asset, $isolatedSymbol, $recvWindow);

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

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