<?php

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

/**
 * Binance Crypto Loan REST API.
 *
 * OpenAPI Specification for the Binance Crypto Loan 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\CryptoLoan\Test\Api;

use Binance\Client\CryptoLoan\Api\FlexibleRateApi;
use Binance\Client\CryptoLoan\Model\FlexibleLoanAdjustLtvRequest;
use Binance\Client\CryptoLoan\Model\FlexibleLoanBorrowRequest;
use Binance\Client\CryptoLoan\Model\FlexibleLoanRepayRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for checkCollateralRepayRate.
     *
     * Check Collateral Repay Rate (USER_DATA).
     */
    public function testCheckCollateralRepayRate()
    {
        $loanCoin = '';
        $collateralCoin = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->checkCollateralRepayRate($loanCoin, $collateralCoin, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/repay/rate', $request->getUri()->getPath());
        self::assertEquals('f49759cc0241450a3fbea110128c62034563a77fc6c27127278cd4e405221aa5', $queryMap['signature']);
    }

    /**
     * Test case for flexibleLoanAdjustLtv.
     *
     * Flexible Loan Adjust LTV(TRADE).
     */
    public function testFlexibleLoanAdjustLtv()
    {
        $flexibleLoanAdjustLtvRequest = new FlexibleLoanAdjustLtvRequest();
        $flexibleLoanAdjustLtvRequest->setLoanCoin('');
        $flexibleLoanAdjustLtvRequest->setCollateralCoin('');
        $flexibleLoanAdjustLtvRequest->setAdjustmentAmount(1.0);
        $flexibleLoanAdjustLtvRequest->setDirection('');

        $response = $this->getApiMock($request)->flexibleLoanAdjustLtv($flexibleLoanAdjustLtvRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/adjust/ltv', $request->getUri()->getPath());
        self::assertEquals('1eecf585c309530c3de30258d7c99fb26eb3f613e7acb65b3e04f8a47314a9ae', $queryMap['signature']);
    }

    /**
     * Test case for flexibleLoanBorrow.
     *
     * Flexible Loan Borrow(TRADE).
     */
    public function testFlexibleLoanBorrow()
    {
        $flexibleLoanBorrowRequest = new FlexibleLoanBorrowRequest();
        $flexibleLoanBorrowRequest->setLoanCoin('');
        $flexibleLoanBorrowRequest->setCollateralCoin('');

        $response = $this->getApiMock($request)->flexibleLoanBorrow($flexibleLoanBorrowRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/borrow', $request->getUri()->getPath());
        self::assertEquals('506923ffabfc7ce18783aec88ca0dee883fa20c5a2b65ea9456eec403ff201ea', $queryMap['signature']);
    }

    /**
     * Test case for flexibleLoanRepay.
     *
     * Flexible Loan Repay(TRADE).
     */
    public function testFlexibleLoanRepay()
    {
        $flexibleLoanRepayRequest = new FlexibleLoanRepayRequest();
        $flexibleLoanRepayRequest->setLoanCoin('');
        $flexibleLoanRepayRequest->setCollateralCoin('');
        $flexibleLoanRepayRequest->setRepayAmount(1.0);

        $response = $this->getApiMock($request)->flexibleLoanRepay($flexibleLoanRepayRequest);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/repay', $request->getUri()->getPath());
        self::assertEquals('dcb96b30d52ea1986fa235b3b062a0eea81f3b5a9e8f2651941dc53d16676028', $queryMap['signature']);
    }

    /**
     * Test case for getFlexibleLoanAssetsData.
     *
     * Get Flexible Loan Assets Data(USER_DATA).
     */
    public function testGetFlexibleLoanAssetsData()
    {
        $loanCoin = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleLoanAssetsData($loanCoin, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/loanable/data', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for getFlexibleLoanBorrowHistory.
     *
     * Get Flexible Loan Borrow History(USER_DATA).
     */
    public function testGetFlexibleLoanBorrowHistory()
    {
        $loanCoin = '';
        $collateralCoin = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $limit = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleLoanBorrowHistory($loanCoin, $collateralCoin, $startTime, $endTime, $current, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/borrow/history', $request->getUri()->getPath());
        self::assertEquals('22ddecc2d8565bd9d57041cec964bd7306916c0004dd0cfd4e227fd3e9bebec4', $queryMap['signature']);
    }

    /**
     * Test case for getFlexibleLoanCollateralAssetsData.
     *
     * Get Flexible Loan Collateral Assets Data(USER_DATA).
     */
    public function testGetFlexibleLoanCollateralAssetsData()
    {
        $collateralCoin = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleLoanCollateralAssetsData($collateralCoin, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/collateral/data', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for getFlexibleLoanLiquidationHistory.
     *
     * Get Flexible Loan Liquidation History (USER_DATA).
     */
    public function testGetFlexibleLoanLiquidationHistory()
    {
        $loanCoin = '';
        $collateralCoin = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $limit = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleLoanLiquidationHistory($loanCoin, $collateralCoin, $startTime, $endTime, $current, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/liquidation/history', $request->getUri()->getPath());
        self::assertEquals('22ddecc2d8565bd9d57041cec964bd7306916c0004dd0cfd4e227fd3e9bebec4', $queryMap['signature']);
    }

    /**
     * Test case for getFlexibleLoanLtvAdjustmentHistory.
     *
     * Get Flexible Loan LTV Adjustment History(USER_DATA).
     */
    public function testGetFlexibleLoanLtvAdjustmentHistory()
    {
        $loanCoin = '';
        $collateralCoin = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $limit = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleLoanLtvAdjustmentHistory($loanCoin, $collateralCoin, $startTime, $endTime, $current, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/ltv/adjustment/history', $request->getUri()->getPath());
        self::assertEquals('22ddecc2d8565bd9d57041cec964bd7306916c0004dd0cfd4e227fd3e9bebec4', $queryMap['signature']);
    }

    /**
     * Test case for getFlexibleLoanOngoingOrders.
     *
     * Get Flexible Loan Ongoing Orders(USER_DATA).
     */
    public function testGetFlexibleLoanOngoingOrders()
    {
        $loanCoin = '';
        $collateralCoin = '';
        $current = 1;
        $limit = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleLoanOngoingOrders($loanCoin, $collateralCoin, $current, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/ongoing/orders', $request->getUri()->getPath());
        self::assertEquals('b3723d8a4f7ae362bec968406a2a68bdebe8825ae14b03114d3c9b3a4ff37904', $queryMap['signature']);
    }

    /**
     * Test case for getFlexibleLoanRepaymentHistory.
     *
     * Get Flexible Loan Repayment History(USER_DATA).
     */
    public function testGetFlexibleLoanRepaymentHistory()
    {
        $loanCoin = '';
        $collateralCoin = '';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $current = 1;
        $limit = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getFlexibleLoanRepaymentHistory($loanCoin, $collateralCoin, $startTime, $endTime, $current, $limit, $recvWindow);

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

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v2/loan/flexible/repay/history', $request->getUri()->getPath());
        self::assertEquals('22ddecc2d8565bd9d57041cec964bd7306916c0004dd0cfd4e227fd3e9bebec4', $queryMap['signature']);
    }
}
