<?php

/**
 * EarnApi
 * 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
 * Do not edit the class manually.
 */

namespace Binance\Client\SimpleEarn\Api;

use Binance\Client\SimpleEarn\Model\GetFlexibleSubscriptionPreviewResponse;
use Binance\Client\SimpleEarn\Model\GetLockedSubscriptionPreviewResponse;
use Binance\Client\SimpleEarn\Model\RedeemFlexibleProductRequest;
use Binance\Client\SimpleEarn\Model\RedeemFlexibleProductResponse;
use Binance\Client\SimpleEarn\Model\RedeemLockedProductRequest;
use Binance\Client\SimpleEarn\Model\RedeemLockedProductResponse;
use Binance\Client\SimpleEarn\Model\SetFlexibleAutoSubscribeRequest;
use Binance\Client\SimpleEarn\Model\SetFlexibleAutoSubscribeResponse;
use Binance\Client\SimpleEarn\Model\SetLockedAutoSubscribeRequest;
use Binance\Client\SimpleEarn\Model\SetLockedAutoSubscribeResponse;
use Binance\Client\SimpleEarn\Model\SetLockedProductRedeemOptionRequest;
use Binance\Client\SimpleEarn\Model\SetLockedProductRedeemOptionResponse;
use Binance\Client\SimpleEarn\Model\SubscribeFlexibleProductRequest;
use Binance\Client\SimpleEarn\Model\SubscribeFlexibleProductResponse;
use Binance\Client\SimpleEarn\Model\SubscribeLockedProductRequest;
use Binance\Client\SimpleEarn\Model\SubscribeLockedProductResponse;
use Binance\Common\ApiException;
use Binance\Common\Auth\SignerFactory;
use Binance\Common\Auth\SignerInterface;
use Binance\Common\CommonUtils;
use Binance\Common\Configuration\ClientConfiguration;
use Binance\Common\Dtos\ApiResponse;
use Binance\Common\HeaderSelector;
use Binance\Common\HttpClient;
use Binance\Common\ObjectSerializer;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Utils;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
 * EarnApi Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */
class EarnApi
{
    /** @var string[] */
    public const contentTypes = [
        'getFlexibleSubscriptionPreview' => ['application/x-www-form-urlencoded'],
        'getLockedSubscriptionPreview' => ['application/x-www-form-urlencoded'],
        'redeemFlexibleProduct' => ['application/x-www-form-urlencoded'],
        'redeemLockedProduct' => ['application/x-www-form-urlencoded'],
        'setFlexibleAutoSubscribe' => ['application/x-www-form-urlencoded'],
        'setLockedAutoSubscribe' => ['application/x-www-form-urlencoded'],
        'setLockedProductRedeemOption' => ['application/x-www-form-urlencoded'],
        'subscribeFlexibleProduct' => ['application/x-www-form-urlencoded'],
        'subscribeLockedProduct' => ['application/x-www-form-urlencoded'],
    ];
    private const HAS_TIME_UNIT = false;

    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var HeaderSelector
     */
    protected $headerSelector;

    /**
     * Summary of clientConfig.
     *
     * @var ClientConfiguration
     */
    protected $clientConfig;

    /**
     * Summary of signer.
     *
     * @var SignerInterface
     */
    protected $signer;

    /**
     * userAgent for HTTP requests.
     *
     * @var string
     */
    private $userAgent;

    public function __construct(
        ?ClientConfiguration $clientConfig = new ClientConfiguration(),
        ?ClientInterface $client = null,
        ?HeaderSelector $selector = null,
    ) {
        $this->clientConfig = $clientConfig;
        $this->client = $client ?: new HttpClient($clientConfig);
        $this->headerSelector = $selector ?: new HeaderSelector();
        if (!empty($clientConfig->getSignatureConfiguration())) {
            $this->signer = SignerFactory::getSigner($clientConfig->getSignatureConfiguration());
        }
        $this->userAgent = CommonUtils::getUserAgent('simple-earn');
    }

    /**
     * Operation getFlexibleSubscriptionPreview.
     *
     * Get Flexible Subscription Preview(USER_DATA)
     *
     * @param string   $productId  productId (required)
     * @param float    $amount     amount (required)
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<GetFlexibleSubscriptionPreviewResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getFlexibleSubscriptionPreview($productId, $amount, $recvWindow = null): ApiResponse
    {
        return $this->getFlexibleSubscriptionPreviewWithHttpInfo($productId, $amount, $recvWindow);
    }

    /**
     * Operation getFlexibleSubscriptionPreviewWithHttpInfo.
     *
     * Get Flexible Subscription Preview(USER_DATA)
     *
     * @param string   $productId  (required)
     * @param float    $amount     (required)
     * @param null|int $recvWindow (optional)
     *
     * @return ApiResponse<GetFlexibleSubscriptionPreviewResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getFlexibleSubscriptionPreviewWithHttpInfo($productId, $amount, $recvWindow = null): ApiResponse
    {
        $request = $this->getFlexibleSubscriptionPreviewRequest($productId, $amount, $recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\SimpleEarn\Model\GetFlexibleSubscriptionPreviewResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\SimpleEarn\Model\GetFlexibleSubscriptionPreviewResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SimpleEarn\Model\GetFlexibleSubscriptionPreviewResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getFlexibleSubscriptionPreview'.
     *
     * @param string   $productId  (required)
     * @param float    $amount     (required)
     * @param null|int $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getFlexibleSubscriptionPreviewRequest($productId, $amount, $recvWindow = null)
    {
        $contentType = self::contentTypes['getFlexibleSubscriptionPreview'][0];

        // verify the required parameter 'productId' is set
        if (null === $productId || (is_array($productId) && 0 === count($productId))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $productId when calling getFlexibleSubscriptionPreview'
            );
        }

        // verify the required parameter 'amount' is set
        if (null === $amount || (is_array($amount) && 0 === count($amount))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amount when calling getFlexibleSubscriptionPreview'
            );
        }

        $resourcePath = '/sapi/v1/simple-earn/flexible/subscriptionPreview';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $productId,
            'productId', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $amount,
            'amount', // param base name
            'number', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getLockedSubscriptionPreview.
     *
     * Get Locked Subscription Preview(USER_DATA)
     *
     * @param string    $projectId     projectId (required)
     * @param float     $amount        amount (required)
     * @param null|bool $autoSubscribe true or false, default true. (optional)
     * @param null|int  $recvWindow    recvWindow (optional)
     *
     * @return ApiResponse<GetLockedSubscriptionPreviewResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getLockedSubscriptionPreview($projectId, $amount, $autoSubscribe = null, $recvWindow = null): ApiResponse
    {
        return $this->getLockedSubscriptionPreviewWithHttpInfo($projectId, $amount, $autoSubscribe, $recvWindow);
    }

    /**
     * Operation getLockedSubscriptionPreviewWithHttpInfo.
     *
     * Get Locked Subscription Preview(USER_DATA)
     *
     * @param string    $projectId     (required)
     * @param float     $amount        (required)
     * @param null|bool $autoSubscribe true or false, default true. (optional)
     * @param null|int  $recvWindow    (optional)
     *
     * @return ApiResponse<GetLockedSubscriptionPreviewResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getLockedSubscriptionPreviewWithHttpInfo($projectId, $amount, $autoSubscribe = null, $recvWindow = null): ApiResponse
    {
        $request = $this->getLockedSubscriptionPreviewRequest($projectId, $amount, $autoSubscribe, $recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\SimpleEarn\Model\GetLockedSubscriptionPreviewResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\SimpleEarn\Model\GetLockedSubscriptionPreviewResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SimpleEarn\Model\GetLockedSubscriptionPreviewResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getLockedSubscriptionPreview'.
     *
     * @param string    $projectId     (required)
     * @param float     $amount        (required)
     * @param null|bool $autoSubscribe true or false, default true. (optional)
     * @param null|int  $recvWindow    (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getLockedSubscriptionPreviewRequest($projectId, $amount, $autoSubscribe = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['getLockedSubscriptionPreview'][0];

        // verify the required parameter 'projectId' is set
        if (null === $projectId || (is_array($projectId) && 0 === count($projectId))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $projectId when calling getLockedSubscriptionPreview'
            );
        }

        // verify the required parameter 'amount' is set
        if (null === $amount || (is_array($amount) && 0 === count($amount))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amount when calling getLockedSubscriptionPreview'
            );
        }

        $resourcePath = '/sapi/v1/simple-earn/locked/subscriptionPreview';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $projectId,
            'projectId', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $amount,
            'amount', // param base name
            'number', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $autoSubscribe,
            'autoSubscribe', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation redeemFlexibleProduct.
     *
     * Redeem Flexible Product(TRADE)
     *
     * @param RedeemFlexibleProductRequest $redeemFlexibleProductRequest redeemFlexibleProductRequest (required)
     *
     * @return ApiResponse<RedeemFlexibleProductResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function redeemFlexibleProduct($redeemFlexibleProductRequest): ApiResponse
    {
        return $this->redeemFlexibleProductWithHttpInfo($redeemFlexibleProductRequest);
    }

    /**
     * Operation redeemFlexibleProductWithHttpInfo.
     *
     * Redeem Flexible Product(TRADE)
     *
     * @param RedeemFlexibleProductRequest $redeemFlexibleProductRequest (required)
     *
     * @return ApiResponse<RedeemFlexibleProductResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function redeemFlexibleProductWithHttpInfo($redeemFlexibleProductRequest): ApiResponse
    {
        $request = $this->redeemFlexibleProductRequest($redeemFlexibleProductRequest);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\SimpleEarn\Model\RedeemFlexibleProductResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\SimpleEarn\Model\RedeemFlexibleProductResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SimpleEarn\Model\RedeemFlexibleProductResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'redeemFlexibleProduct'.
     *
     * @param RedeemFlexibleProductRequest $redeemFlexibleProductRequest (required)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function redeemFlexibleProductRequest($redeemFlexibleProductRequest)
    {
        $contentType = self::contentTypes['redeemFlexibleProduct'][0];

        // verify the required parameter 'redeemFlexibleProductRequest' is set
        if (null === $redeemFlexibleProductRequest || (is_array($redeemFlexibleProductRequest) && 0 === count($redeemFlexibleProductRequest))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $redeemFlexibleProductRequest when calling redeemFlexibleProduct'
            );
        }

        $resourcePath = '/sapi/v1/simple-earn/flexible/redeem';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $redeemFlexibleProductRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $redeemFlexibleProductRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $redeemFlexibleProductRequest->{$getter}();
            }
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        } elseif (isset($redeemFlexibleProductRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($redeemFlexibleProductRequest));
            } else {
                $httpBody = $redeemFlexibleProductRequest;
            }
        }

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'POST',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation redeemLockedProduct.
     *
     * Redeem Locked Product(TRADE)
     *
     * @param RedeemLockedProductRequest $redeemLockedProductRequest redeemLockedProductRequest (required)
     *
     * @return ApiResponse<RedeemLockedProductResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function redeemLockedProduct($redeemLockedProductRequest): ApiResponse
    {
        return $this->redeemLockedProductWithHttpInfo($redeemLockedProductRequest);
    }

    /**
     * Operation redeemLockedProductWithHttpInfo.
     *
     * Redeem Locked Product(TRADE)
     *
     * @param RedeemLockedProductRequest $redeemLockedProductRequest (required)
     *
     * @return ApiResponse<RedeemLockedProductResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function redeemLockedProductWithHttpInfo($redeemLockedProductRequest): ApiResponse
    {
        $request = $this->redeemLockedProductRequest($redeemLockedProductRequest);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\SimpleEarn\Model\RedeemLockedProductResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\SimpleEarn\Model\RedeemLockedProductResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SimpleEarn\Model\RedeemLockedProductResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'redeemLockedProduct'.
     *
     * @param RedeemLockedProductRequest $redeemLockedProductRequest (required)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function redeemLockedProductRequest($redeemLockedProductRequest)
    {
        $contentType = self::contentTypes['redeemLockedProduct'][0];

        // verify the required parameter 'redeemLockedProductRequest' is set
        if (null === $redeemLockedProductRequest || (is_array($redeemLockedProductRequest) && 0 === count($redeemLockedProductRequest))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $redeemLockedProductRequest when calling redeemLockedProduct'
            );
        }

        $resourcePath = '/sapi/v1/simple-earn/locked/redeem';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $redeemLockedProductRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $redeemLockedProductRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $redeemLockedProductRequest->{$getter}();
            }
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        } elseif (isset($redeemLockedProductRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($redeemLockedProductRequest));
            } else {
                $httpBody = $redeemLockedProductRequest;
            }
        }

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'POST',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation setFlexibleAutoSubscribe.
     *
     * Set Flexible Auto Subscribe(USER_DATA)
     *
     * @param SetFlexibleAutoSubscribeRequest $setFlexibleAutoSubscribeRequest setFlexibleAutoSubscribeRequest (required)
     *
     * @return ApiResponse<SetFlexibleAutoSubscribeResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function setFlexibleAutoSubscribe($setFlexibleAutoSubscribeRequest): ApiResponse
    {
        return $this->setFlexibleAutoSubscribeWithHttpInfo($setFlexibleAutoSubscribeRequest);
    }

    /**
     * Operation setFlexibleAutoSubscribeWithHttpInfo.
     *
     * Set Flexible Auto Subscribe(USER_DATA)
     *
     * @param SetFlexibleAutoSubscribeRequest $setFlexibleAutoSubscribeRequest (required)
     *
     * @return ApiResponse<SetFlexibleAutoSubscribeResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function setFlexibleAutoSubscribeWithHttpInfo($setFlexibleAutoSubscribeRequest): ApiResponse
    {
        $request = $this->setFlexibleAutoSubscribeRequest($setFlexibleAutoSubscribeRequest);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\SimpleEarn\Model\SetFlexibleAutoSubscribeResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\SimpleEarn\Model\SetFlexibleAutoSubscribeResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SimpleEarn\Model\SetFlexibleAutoSubscribeResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'setFlexibleAutoSubscribe'.
     *
     * @param SetFlexibleAutoSubscribeRequest $setFlexibleAutoSubscribeRequest (required)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function setFlexibleAutoSubscribeRequest($setFlexibleAutoSubscribeRequest)
    {
        $contentType = self::contentTypes['setFlexibleAutoSubscribe'][0];

        // verify the required parameter 'setFlexibleAutoSubscribeRequest' is set
        if (null === $setFlexibleAutoSubscribeRequest || (is_array($setFlexibleAutoSubscribeRequest) && 0 === count($setFlexibleAutoSubscribeRequest))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $setFlexibleAutoSubscribeRequest when calling setFlexibleAutoSubscribe'
            );
        }

        $resourcePath = '/sapi/v1/simple-earn/flexible/setAutoSubscribe';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $setFlexibleAutoSubscribeRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $setFlexibleAutoSubscribeRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $setFlexibleAutoSubscribeRequest->{$getter}();
            }
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        } elseif (isset($setFlexibleAutoSubscribeRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($setFlexibleAutoSubscribeRequest));
            } else {
                $httpBody = $setFlexibleAutoSubscribeRequest;
            }
        }

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'POST',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation setLockedAutoSubscribe.
     *
     * Set Locked Auto Subscribe(USER_DATA)
     *
     * @param SetLockedAutoSubscribeRequest $setLockedAutoSubscribeRequest setLockedAutoSubscribeRequest (required)
     *
     * @return ApiResponse<SetLockedAutoSubscribeResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function setLockedAutoSubscribe($setLockedAutoSubscribeRequest): ApiResponse
    {
        return $this->setLockedAutoSubscribeWithHttpInfo($setLockedAutoSubscribeRequest);
    }

    /**
     * Operation setLockedAutoSubscribeWithHttpInfo.
     *
     * Set Locked Auto Subscribe(USER_DATA)
     *
     * @param SetLockedAutoSubscribeRequest $setLockedAutoSubscribeRequest (required)
     *
     * @return ApiResponse<SetLockedAutoSubscribeResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function setLockedAutoSubscribeWithHttpInfo($setLockedAutoSubscribeRequest): ApiResponse
    {
        $request = $this->setLockedAutoSubscribeRequest($setLockedAutoSubscribeRequest);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\SimpleEarn\Model\SetLockedAutoSubscribeResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\SimpleEarn\Model\SetLockedAutoSubscribeResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SimpleEarn\Model\SetLockedAutoSubscribeResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'setLockedAutoSubscribe'.
     *
     * @param SetLockedAutoSubscribeRequest $setLockedAutoSubscribeRequest (required)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function setLockedAutoSubscribeRequest($setLockedAutoSubscribeRequest)
    {
        $contentType = self::contentTypes['setLockedAutoSubscribe'][0];

        // verify the required parameter 'setLockedAutoSubscribeRequest' is set
        if (null === $setLockedAutoSubscribeRequest || (is_array($setLockedAutoSubscribeRequest) && 0 === count($setLockedAutoSubscribeRequest))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $setLockedAutoSubscribeRequest when calling setLockedAutoSubscribe'
            );
        }

        $resourcePath = '/sapi/v1/simple-earn/locked/setAutoSubscribe';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $setLockedAutoSubscribeRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $setLockedAutoSubscribeRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $setLockedAutoSubscribeRequest->{$getter}();
            }
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        } elseif (isset($setLockedAutoSubscribeRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($setLockedAutoSubscribeRequest));
            } else {
                $httpBody = $setLockedAutoSubscribeRequest;
            }
        }

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'POST',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation setLockedProductRedeemOption.
     *
     * Set Locked Product Redeem Option(USER_DATA)
     *
     * @param SetLockedProductRedeemOptionRequest $setLockedProductRedeemOptionRequest setLockedProductRedeemOptionRequest (required)
     *
     * @return ApiResponse<SetLockedProductRedeemOptionResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function setLockedProductRedeemOption($setLockedProductRedeemOptionRequest): ApiResponse
    {
        return $this->setLockedProductRedeemOptionWithHttpInfo($setLockedProductRedeemOptionRequest);
    }

    /**
     * Operation setLockedProductRedeemOptionWithHttpInfo.
     *
     * Set Locked Product Redeem Option(USER_DATA)
     *
     * @param SetLockedProductRedeemOptionRequest $setLockedProductRedeemOptionRequest (required)
     *
     * @return ApiResponse<SetLockedProductRedeemOptionResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function setLockedProductRedeemOptionWithHttpInfo($setLockedProductRedeemOptionRequest): ApiResponse
    {
        $request = $this->setLockedProductRedeemOptionRequest($setLockedProductRedeemOptionRequest);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\SimpleEarn\Model\SetLockedProductRedeemOptionResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\SimpleEarn\Model\SetLockedProductRedeemOptionResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SimpleEarn\Model\SetLockedProductRedeemOptionResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'setLockedProductRedeemOption'.
     *
     * @param SetLockedProductRedeemOptionRequest $setLockedProductRedeemOptionRequest (required)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function setLockedProductRedeemOptionRequest($setLockedProductRedeemOptionRequest)
    {
        $contentType = self::contentTypes['setLockedProductRedeemOption'][0];

        // verify the required parameter 'setLockedProductRedeemOptionRequest' is set
        if (null === $setLockedProductRedeemOptionRequest || (is_array($setLockedProductRedeemOptionRequest) && 0 === count($setLockedProductRedeemOptionRequest))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $setLockedProductRedeemOptionRequest when calling setLockedProductRedeemOption'
            );
        }

        $resourcePath = '/sapi/v1/simple-earn/locked/setRedeemOption';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $setLockedProductRedeemOptionRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $setLockedProductRedeemOptionRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $setLockedProductRedeemOptionRequest->{$getter}();
            }
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        } elseif (isset($setLockedProductRedeemOptionRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($setLockedProductRedeemOptionRequest));
            } else {
                $httpBody = $setLockedProductRedeemOptionRequest;
            }
        }

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'POST',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation subscribeFlexibleProduct.
     *
     * Subscribe Flexible Product(TRADE)
     *
     * @param SubscribeFlexibleProductRequest $subscribeFlexibleProductRequest subscribeFlexibleProductRequest (required)
     *
     * @return ApiResponse<SubscribeFlexibleProductResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function subscribeFlexibleProduct($subscribeFlexibleProductRequest): ApiResponse
    {
        return $this->subscribeFlexibleProductWithHttpInfo($subscribeFlexibleProductRequest);
    }

    /**
     * Operation subscribeFlexibleProductWithHttpInfo.
     *
     * Subscribe Flexible Product(TRADE)
     *
     * @param SubscribeFlexibleProductRequest $subscribeFlexibleProductRequest (required)
     *
     * @return ApiResponse<SubscribeFlexibleProductResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function subscribeFlexibleProductWithHttpInfo($subscribeFlexibleProductRequest): ApiResponse
    {
        $request = $this->subscribeFlexibleProductRequest($subscribeFlexibleProductRequest);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\SimpleEarn\Model\SubscribeFlexibleProductResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\SimpleEarn\Model\SubscribeFlexibleProductResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SimpleEarn\Model\SubscribeFlexibleProductResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'subscribeFlexibleProduct'.
     *
     * @param SubscribeFlexibleProductRequest $subscribeFlexibleProductRequest (required)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function subscribeFlexibleProductRequest($subscribeFlexibleProductRequest)
    {
        $contentType = self::contentTypes['subscribeFlexibleProduct'][0];

        // verify the required parameter 'subscribeFlexibleProductRequest' is set
        if (null === $subscribeFlexibleProductRequest || (is_array($subscribeFlexibleProductRequest) && 0 === count($subscribeFlexibleProductRequest))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $subscribeFlexibleProductRequest when calling subscribeFlexibleProduct'
            );
        }

        $resourcePath = '/sapi/v1/simple-earn/flexible/subscribe';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $subscribeFlexibleProductRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $subscribeFlexibleProductRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $subscribeFlexibleProductRequest->{$getter}();
            }
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        } elseif (isset($subscribeFlexibleProductRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($subscribeFlexibleProductRequest));
            } else {
                $httpBody = $subscribeFlexibleProductRequest;
            }
        }

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'POST',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation subscribeLockedProduct.
     *
     * Subscribe Locked Product(TRADE)
     *
     * @param SubscribeLockedProductRequest $subscribeLockedProductRequest subscribeLockedProductRequest (required)
     *
     * @return ApiResponse<SubscribeLockedProductResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function subscribeLockedProduct($subscribeLockedProductRequest): ApiResponse
    {
        return $this->subscribeLockedProductWithHttpInfo($subscribeLockedProductRequest);
    }

    /**
     * Operation subscribeLockedProductWithHttpInfo.
     *
     * Subscribe Locked Product(TRADE)
     *
     * @param SubscribeLockedProductRequest $subscribeLockedProductRequest (required)
     *
     * @return ApiResponse<SubscribeLockedProductResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function subscribeLockedProductWithHttpInfo($subscribeLockedProductRequest): ApiResponse
    {
        $request = $this->subscribeLockedProductRequest($subscribeLockedProductRequest);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\SimpleEarn\Model\SubscribeLockedProductResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\SimpleEarn\Model\SubscribeLockedProductResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SimpleEarn\Model\SubscribeLockedProductResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'subscribeLockedProduct'.
     *
     * @param SubscribeLockedProductRequest $subscribeLockedProductRequest (required)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function subscribeLockedProductRequest($subscribeLockedProductRequest)
    {
        $contentType = self::contentTypes['subscribeLockedProduct'][0];

        // verify the required parameter 'subscribeLockedProductRequest' is set
        if (null === $subscribeLockedProductRequest || (is_array($subscribeLockedProductRequest) && 0 === count($subscribeLockedProductRequest))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $subscribeLockedProductRequest when calling subscribeLockedProduct'
            );
        }

        $resourcePath = '/sapi/v1/simple-earn/locked/subscribe';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $subscribeLockedProductRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $subscribeLockedProductRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $subscribeLockedProductRequest->{$getter}();
            }
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        } elseif (isset($subscribeLockedProductRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($subscribeLockedProductRequest));
            } else {
                $httpBody = $subscribeLockedProductRequest;
            }
        }

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'POST',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Summary of getTimestamp.
     */
    public function getTimestamp(): string
    {
        return date_create()->format('Uv');
    }

    private function handleResponseWithDataType(
        string $dataType,
        RequestInterface $request,
        ResponseInterface $response
    ): ApiResponse {
        if ('\SplFileObject' === $dataType) {
            $content = $response->getBody(); // stream goes to serializer
        } else {
            $content = (string) $response->getBody();
            if ('string' !== $dataType) {
                try {
                    $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
                } catch (\JsonException $exception) {
                    throw new ApiException(
                        sprintf(
                            'Error JSON decoding server response (%s)',
                            $request->getUri()
                        ),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                        $content
                    );
                }
            }
        }

        $rateLimits = CommonUtils::getRateLimits($response->getStatusCode(), $response->getHeaders());

        return new ApiResponse(
            $response->getStatusCode(),
            $response->getHeaders(),
            ObjectSerializer::deserialize($content, $dataType, []),
            $rateLimits
        );
    }

    private function responseWithinRangeCode(
        string $rangeCode,
        int $statusCode
    ): bool {
        $left = (int) ($rangeCode[0].'00');
        $right = (int) ($rangeCode[0].'99');

        return $statusCode >= $left && $statusCode <= $right;
    }
}
