<?php

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

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

use Binance\Client\VipLoan\Api\TradeApi;
use Binance\Client\VipLoan\Model\VipLoanBorrowRequest;
use Binance\Client\VipLoan\Model\VipLoanRenewRequest;
use Binance\Client\VipLoan\Model\VipLoanRepayRequest;
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;

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

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

        return $apiMock;
    }

    /**
     * Test case for vipLoanBorrow.
     *
     * VIP Loan Borrow(TRADE).
     */
    public function testVipLoanBorrow()
    {
        $vipLoanBorrowRequest = new VipLoanBorrowRequest();
        $vipLoanBorrowRequest->setLoanAccountId(1);
        $vipLoanBorrowRequest->setLoanCoin('');
        $vipLoanBorrowRequest->setLoanAmount(1.0);
        $vipLoanBorrowRequest->setCollateralAccountId(1);
        $vipLoanBorrowRequest->setCollateralCoin('');
        $vipLoanBorrowRequest->setIsFlexibleRate(true);

        $response = $this->getApiMock($request)->vipLoanBorrow($vipLoanBorrowRequest);

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

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

    /**
     * Test case for vipLoanRenew.
     *
     * VIP Loan Renew(TRADE).
     */
    public function testVipLoanRenew()
    {
        $vipLoanRenewRequest = new VipLoanRenewRequest();
        $vipLoanRenewRequest->setOrderId(1);
        $vipLoanRenewRequest->setLoanTerm(1);

        $response = $this->getApiMock($request)->vipLoanRenew($vipLoanRenewRequest);

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

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

    /**
     * Test case for vipLoanRepay.
     *
     * VIP Loan Repay(TRADE).
     */
    public function testVipLoanRepay()
    {
        $vipLoanRepayRequest = new VipLoanRepayRequest();
        $vipLoanRepayRequest->setOrderId(1);
        $vipLoanRepayRequest->setAmount(1.0);

        $response = $this->getApiMock($request)->vipLoanRepay($vipLoanRepayRequest);

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

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