<?php
/**
 * PartnerBillingApi
 * PHP version 8.1
 *
 * @category Class
 * @package  Vend202601
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * API 2026-01
 *
 * Lightspeed Retail (X-Series) API.
 *
 * The version of the OpenAPI document: 2026-01
 * Contact: x-series.api@lightspeedhq.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.21.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 Vend202601\Api;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Vend202601\ApiException;
use Vend202601\Configuration;
use Vend202601\FormDataProcessor;
use Vend202601\HeaderSelector;
use Vend202601\ObjectSerializer;

/**
 * PartnerBillingApi Class Doc Comment
 *
 * @category Class
 * @package  Vend202601
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */
class PartnerBillingApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var Configuration
     */
    protected $config;

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

    /**
     * @var int Host index
     */
    protected $hostIndex;

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'partnerSubscription' => [
            'application/json',
        ],
        'partnerSubscriptions' => [
            'application/json',
        ],
        'partnerToken' => [
            'application/json',
        ],
        'partnerTokenGet' => [
            'application/json',
        ],
        'partnerUpdateSubscriptionToken' => [
            'application/json',
        ],
    ];

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     * @param int             $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
     */
    public function __construct(
        ?ClientInterface $client = null,
        ?Configuration $config = null,
        ?HeaderSelector $selector = null,
        int $hostIndex = 0
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: Configuration::getDefaultConfiguration();
        $this->headerSelector = $selector ?: new HeaderSelector();
        $this->hostIndex = $hostIndex;
    }

    /**
     * Set the host index
     *
     * @param int $hostIndex Host index (required)
     */
    public function setHostIndex($hostIndex): void
    {
        $this->hostIndex = $hostIndex;
    }

    /**
     * Get the host index
     *
     * @return int Host index
     */
    public function getHostIndex()
    {
        return $this->hostIndex;
    }

    /**
     * @return Configuration
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * Operation partnerSubscription
     *
     * Get a partner subscription
     *
     * @param  string $subscription_id subscription_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscription'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend202601\Model\PartnerSubscription200Response
     */
    public function partnerSubscription($subscription_id, string $contentType = self::contentTypes['partnerSubscription'][0])
    {
        list($response) = $this->partnerSubscriptionWithHttpInfo($subscription_id, $contentType);
        return $response;
    }

    /**
     * Operation partnerSubscriptionWithHttpInfo
     *
     * Get a partner subscription
     *
     * @param  string $subscription_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscription'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend202601\Model\PartnerSubscription200Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function partnerSubscriptionWithHttpInfo($subscription_id, string $contentType = self::contentTypes['partnerSubscription'][0])
    {
        $request = $this->partnerSubscriptionRequest($subscription_id, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } 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(
                        '\Vend202601\Model\PartnerSubscription200Response',
                        $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(
                '\Vend202601\Model\PartnerSubscription200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PartnerSubscription200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation partnerSubscriptionAsync
     *
     * Get a partner subscription
     *
     * @param  string $subscription_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscription'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerSubscriptionAsync($subscription_id, string $contentType = self::contentTypes['partnerSubscription'][0])
    {
        return $this->partnerSubscriptionAsyncWithHttpInfo($subscription_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation partnerSubscriptionAsyncWithHttpInfo
     *
     * Get a partner subscription
     *
     * @param  string $subscription_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscription'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerSubscriptionAsyncWithHttpInfo($subscription_id, string $contentType = self::contentTypes['partnerSubscription'][0])
    {
        $returnType = '\Vend202601\Model\PartnerSubscription200Response';
        $request = $this->partnerSubscriptionRequest($subscription_id, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'partnerSubscription'
     *
     * @param  string $subscription_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscription'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function partnerSubscriptionRequest($subscription_id, string $contentType = self::contentTypes['partnerSubscription'][0])
    {

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


        $resourcePath = '/partner/billing/subscriptions/{subscription_id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($subscription_id !== null) {
            $resourcePath = str_replace(
                '{' . 'subscription_id' . '}',
                ObjectSerializer::toPathValue($subscription_id),
                $resourcePath
            );
        }


        $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 (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires Bearer authentication (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation partnerSubscriptions
     *
     * List partner subscriptions
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscriptions'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend202601\Model\PartnerSubscriptions200Response
     */
    public function partnerSubscriptions(string $contentType = self::contentTypes['partnerSubscriptions'][0])
    {
        list($response) = $this->partnerSubscriptionsWithHttpInfo($contentType);
        return $response;
    }

    /**
     * Operation partnerSubscriptionsWithHttpInfo
     *
     * List partner subscriptions
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscriptions'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend202601\Model\PartnerSubscriptions200Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function partnerSubscriptionsWithHttpInfo(string $contentType = self::contentTypes['partnerSubscriptions'][0])
    {
        $request = $this->partnerSubscriptionsRequest($contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } 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(
                        '\Vend202601\Model\PartnerSubscriptions200Response',
                        $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(
                '\Vend202601\Model\PartnerSubscriptions200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PartnerSubscriptions200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation partnerSubscriptionsAsync
     *
     * List partner subscriptions
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscriptions'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerSubscriptionsAsync(string $contentType = self::contentTypes['partnerSubscriptions'][0])
    {
        return $this->partnerSubscriptionsAsyncWithHttpInfo($contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation partnerSubscriptionsAsyncWithHttpInfo
     *
     * List partner subscriptions
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscriptions'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerSubscriptionsAsyncWithHttpInfo(string $contentType = self::contentTypes['partnerSubscriptions'][0])
    {
        $returnType = '\Vend202601\Model\PartnerSubscriptions200Response';
        $request = $this->partnerSubscriptionsRequest($contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'partnerSubscriptions'
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerSubscriptions'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function partnerSubscriptionsRequest(string $contentType = self::contentTypes['partnerSubscriptions'][0])
    {


        $resourcePath = '/partner/billing/subscriptions';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;





        $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 (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires Bearer authentication (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation partnerToken
     *
     * Create a partner subscription token
     *
     * @param  \Vend202601\Model\PartnerSubscriptionTokenRequest $partner_subscription_token_request partner_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerToken'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend202601\Model\PartnerToken200Response
     */
    public function partnerToken($partner_subscription_token_request, string $contentType = self::contentTypes['partnerToken'][0])
    {
        list($response) = $this->partnerTokenWithHttpInfo($partner_subscription_token_request, $contentType);
        return $response;
    }

    /**
     * Operation partnerTokenWithHttpInfo
     *
     * Create a partner subscription token
     *
     * @param  \Vend202601\Model\PartnerSubscriptionTokenRequest $partner_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerToken'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend202601\Model\PartnerToken200Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function partnerTokenWithHttpInfo($partner_subscription_token_request, string $contentType = self::contentTypes['partnerToken'][0])
    {
        $request = $this->partnerTokenRequest($partner_subscription_token_request, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } 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(
                        '\Vend202601\Model\PartnerToken200Response',
                        $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(
                '\Vend202601\Model\PartnerToken200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PartnerToken200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation partnerTokenAsync
     *
     * Create a partner subscription token
     *
     * @param  \Vend202601\Model\PartnerSubscriptionTokenRequest $partner_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerToken'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerTokenAsync($partner_subscription_token_request, string $contentType = self::contentTypes['partnerToken'][0])
    {
        return $this->partnerTokenAsyncWithHttpInfo($partner_subscription_token_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation partnerTokenAsyncWithHttpInfo
     *
     * Create a partner subscription token
     *
     * @param  \Vend202601\Model\PartnerSubscriptionTokenRequest $partner_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerToken'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerTokenAsyncWithHttpInfo($partner_subscription_token_request, string $contentType = self::contentTypes['partnerToken'][0])
    {
        $returnType = '\Vend202601\Model\PartnerToken200Response';
        $request = $this->partnerTokenRequest($partner_subscription_token_request, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'partnerToken'
     *
     * @param  \Vend202601\Model\PartnerSubscriptionTokenRequest $partner_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerToken'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function partnerTokenRequest($partner_subscription_token_request, string $contentType = self::contentTypes['partnerToken'][0])
    {

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


        $resourcePath = '/partner/billing/token';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;





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

        // for model (json/xml)
        if (isset($partner_subscription_token_request)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($partner_subscription_token_request));
            } else {
                $httpBody = $partner_subscription_token_request;
            }
        } elseif (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 (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires Bearer authentication (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'POST',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation partnerTokenGet
     *
     * Get subscription by token
     *
     * @param  string $partner_subscription_token The partner subscription token (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerTokenGet'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend202601\Model\PartnerTokenGet200Response
     */
    public function partnerTokenGet($partner_subscription_token, string $contentType = self::contentTypes['partnerTokenGet'][0])
    {
        list($response) = $this->partnerTokenGetWithHttpInfo($partner_subscription_token, $contentType);
        return $response;
    }

    /**
     * Operation partnerTokenGetWithHttpInfo
     *
     * Get subscription by token
     *
     * @param  string $partner_subscription_token The partner subscription token (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerTokenGet'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend202601\Model\PartnerTokenGet200Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function partnerTokenGetWithHttpInfo($partner_subscription_token, string $contentType = self::contentTypes['partnerTokenGet'][0])
    {
        $request = $this->partnerTokenGetRequest($partner_subscription_token, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } 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(
                        '\Vend202601\Model\PartnerTokenGet200Response',
                        $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(
                '\Vend202601\Model\PartnerTokenGet200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PartnerTokenGet200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation partnerTokenGetAsync
     *
     * Get subscription by token
     *
     * @param  string $partner_subscription_token The partner subscription token (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerTokenGet'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerTokenGetAsync($partner_subscription_token, string $contentType = self::contentTypes['partnerTokenGet'][0])
    {
        return $this->partnerTokenGetAsyncWithHttpInfo($partner_subscription_token, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation partnerTokenGetAsyncWithHttpInfo
     *
     * Get subscription by token
     *
     * @param  string $partner_subscription_token The partner subscription token (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerTokenGet'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerTokenGetAsyncWithHttpInfo($partner_subscription_token, string $contentType = self::contentTypes['partnerTokenGet'][0])
    {
        $returnType = '\Vend202601\Model\PartnerTokenGet200Response';
        $request = $this->partnerTokenGetRequest($partner_subscription_token, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'partnerTokenGet'
     *
     * @param  string $partner_subscription_token The partner subscription token (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerTokenGet'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function partnerTokenGetRequest($partner_subscription_token, string $contentType = self::contentTypes['partnerTokenGet'][0])
    {

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


        $resourcePath = '/partner/billing/token/{partner_subscription_token}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($partner_subscription_token !== null) {
            $resourcePath = str_replace(
                '{' . 'partner_subscription_token' . '}',
                ObjectSerializer::toPathValue($partner_subscription_token),
                $resourcePath
            );
        }


        $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 (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires Bearer authentication (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation partnerUpdateSubscriptionToken
     *
     * Create a partner update subscription token
     *
     * @param  \Vend202601\Model\PartnerUpdateSubscriptionTokenRequest $partner_update_subscription_token_request partner_update_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerUpdateSubscriptionToken'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend202601\Model\PartnerToken200Response
     */
    public function partnerUpdateSubscriptionToken($partner_update_subscription_token_request, string $contentType = self::contentTypes['partnerUpdateSubscriptionToken'][0])
    {
        list($response) = $this->partnerUpdateSubscriptionTokenWithHttpInfo($partner_update_subscription_token_request, $contentType);
        return $response;
    }

    /**
     * Operation partnerUpdateSubscriptionTokenWithHttpInfo
     *
     * Create a partner update subscription token
     *
     * @param  \Vend202601\Model\PartnerUpdateSubscriptionTokenRequest $partner_update_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerUpdateSubscriptionToken'] to see the possible values for this operation
     *
     * @throws \Vend202601\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend202601\Model\PartnerToken200Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function partnerUpdateSubscriptionTokenWithHttpInfo($partner_update_subscription_token_request, string $contentType = self::contentTypes['partnerUpdateSubscriptionToken'][0])
    {
        $request = $this->partnerUpdateSubscriptionTokenRequest($partner_update_subscription_token_request, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } 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(
                        '\Vend202601\Model\PartnerToken200Response',
                        $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(
                '\Vend202601\Model\PartnerToken200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PartnerToken200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation partnerUpdateSubscriptionTokenAsync
     *
     * Create a partner update subscription token
     *
     * @param  \Vend202601\Model\PartnerUpdateSubscriptionTokenRequest $partner_update_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerUpdateSubscriptionToken'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerUpdateSubscriptionTokenAsync($partner_update_subscription_token_request, string $contentType = self::contentTypes['partnerUpdateSubscriptionToken'][0])
    {
        return $this->partnerUpdateSubscriptionTokenAsyncWithHttpInfo($partner_update_subscription_token_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation partnerUpdateSubscriptionTokenAsyncWithHttpInfo
     *
     * Create a partner update subscription token
     *
     * @param  \Vend202601\Model\PartnerUpdateSubscriptionTokenRequest $partner_update_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerUpdateSubscriptionToken'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function partnerUpdateSubscriptionTokenAsyncWithHttpInfo($partner_update_subscription_token_request, string $contentType = self::contentTypes['partnerUpdateSubscriptionToken'][0])
    {
        $returnType = '\Vend202601\Model\PartnerToken200Response';
        $request = $this->partnerUpdateSubscriptionTokenRequest($partner_update_subscription_token_request, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'partnerUpdateSubscriptionToken'
     *
     * @param  \Vend202601\Model\PartnerUpdateSubscriptionTokenRequest $partner_update_subscription_token_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['partnerUpdateSubscriptionToken'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function partnerUpdateSubscriptionTokenRequest($partner_update_subscription_token_request, string $contentType = self::contentTypes['partnerUpdateSubscriptionToken'][0])
    {

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


        $resourcePath = '/partner/billing/update-subscription/token';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;





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

        // for model (json/xml)
        if (isset($partner_update_subscription_token_request)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($partner_update_subscription_token_request));
            } else {
                $httpBody = $partner_update_subscription_token_request;
            }
        } elseif (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 (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires Bearer authentication (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'POST',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option
     *
     * @throws \RuntimeException on file opening failure
     * @return array of http client options
     */
    protected function createHttpClientOption()
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
            }
        }

        if ($this->config->getCertFile()) {
            $options[RequestOptions::CERT] = $this->config->getCertFile();
        }

        if ($this->config->getKeyFile()) {
            $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
        }

        return $options;
    }

    private function handleResponseWithDataType(
        string $dataType,
        RequestInterface $request,
        ResponseInterface $response
    ): array {
        if ($dataType === '\SplFileObject') {
            $content = $response->getBody(); //stream goes to serializer
        } else {
            $content = (string) $response->getBody();
            if ($dataType !== 'string') {
                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
                    );
                }
            }
        }

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

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

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