<?php

/**
 * StableRateApiTest
 * 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\StableRateApi;
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;

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

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

        return $apiMock;
    }

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

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

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

    /**
     * Test case for getCryptoLoansIncomeHistory.
     *
     * Get Crypto Loans Income History(USER_DATA).
     */
    public function testGetCryptoLoansIncomeHistory()
    {
        $asset = '';
        $type = '0';
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getCryptoLoansIncomeHistory($asset, $type, $startTime, $endTime, $limit, $recvWindow);

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

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

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

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

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

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

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

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

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

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

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