<?php
/**
 * VariantAttributesApi
 * 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.20.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;

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'createVariantAttribute' => [
            'application/json',
        ],
        'deleteVariantAttribute' => [
            'application/json',
        ],
        'getVariantAttributes' => [
            'application/json',
        ],
        'listVariantAttributes' => [
            'application/json',
        ],
        'updateVariantAttribute' => [
            '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 createVariantAttribute
     *
     * Create a Variant Attribute
     *
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createVariantAttribute'] 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\VariantAttributeCreateResponse|object
     */
    public function createVariantAttribute($variant_attribute_create_update_body, string $contentType = self::contentTypes['createVariantAttribute'][0])
    {
        list($response) = $this->createVariantAttributeWithHttpInfo($variant_attribute_create_update_body, $contentType);
        return $response;
    }

    /**
     * Operation createVariantAttributeWithHttpInfo
     *
     * Create a Variant Attribute
     *
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createVariantAttribute'] 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\VariantAttributeCreateResponse|object, HTTP status code, HTTP response headers (array of strings)
     */
    public function createVariantAttributeWithHttpInfo($variant_attribute_create_update_body, string $contentType = self::contentTypes['createVariantAttribute'][0])
    {
        $request = $this->createVariantAttributeRequest($variant_attribute_create_update_body, $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 201:
                    return $this->handleResponseWithDataType(
                        '\Vend202601\Model\VariantAttributeCreateResponse',
                        $request,
                        $response,
                    );
                case 422:
                    return $this->handleResponseWithDataType(
                        'object',
                        $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\VariantAttributeCreateResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\VariantAttributeCreateResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 422:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'object',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation createVariantAttributeAsync
     *
     * Create a Variant Attribute
     *
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createVariantAttribute'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createVariantAttributeAsync($variant_attribute_create_update_body, string $contentType = self::contentTypes['createVariantAttribute'][0])
    {
        return $this->createVariantAttributeAsyncWithHttpInfo($variant_attribute_create_update_body, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation createVariantAttributeAsyncWithHttpInfo
     *
     * Create a Variant Attribute
     *
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createVariantAttribute'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createVariantAttributeAsyncWithHttpInfo($variant_attribute_create_update_body, string $contentType = self::contentTypes['createVariantAttribute'][0])
    {
        $returnType = '\Vend202601\Model\VariantAttributeCreateResponse';
        $request = $this->createVariantAttributeRequest($variant_attribute_create_update_body, $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 'createVariantAttribute'
     *
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createVariantAttribute'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function createVariantAttributeRequest($variant_attribute_create_update_body, string $contentType = self::contentTypes['createVariantAttribute'][0])
    {

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


        $resourcePath = '/variant_attributes';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;





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

        // for model (json/xml)
        if (isset($variant_attribute_create_update_body)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($variant_attribute_create_update_body));
            } else {
                $httpBody = $variant_attribute_create_update_body;
            }
        } 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 deleteVariantAttribute
     *
     * Delete a variant attribute
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to delete. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteVariantAttribute'] 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\VariantAttributeDeleteResponse|object
     */
    public function deleteVariantAttribute($attribute_id, string $contentType = self::contentTypes['deleteVariantAttribute'][0])
    {
        list($response) = $this->deleteVariantAttributeWithHttpInfo($attribute_id, $contentType);
        return $response;
    }

    /**
     * Operation deleteVariantAttributeWithHttpInfo
     *
     * Delete a variant attribute
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to delete. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteVariantAttribute'] 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\VariantAttributeDeleteResponse|object, HTTP status code, HTTP response headers (array of strings)
     */
    public function deleteVariantAttributeWithHttpInfo($attribute_id, string $contentType = self::contentTypes['deleteVariantAttribute'][0])
    {
        $request = $this->deleteVariantAttributeRequest($attribute_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\VariantAttributeDeleteResponse',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        'object',
                        $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\VariantAttributeDeleteResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\VariantAttributeDeleteResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'object',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation deleteVariantAttributeAsync
     *
     * Delete a variant attribute
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to delete. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteVariantAttribute'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteVariantAttributeAsync($attribute_id, string $contentType = self::contentTypes['deleteVariantAttribute'][0])
    {
        return $this->deleteVariantAttributeAsyncWithHttpInfo($attribute_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteVariantAttributeAsyncWithHttpInfo
     *
     * Delete a variant attribute
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to delete. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteVariantAttribute'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteVariantAttributeAsyncWithHttpInfo($attribute_id, string $contentType = self::contentTypes['deleteVariantAttribute'][0])
    {
        $returnType = '\Vend202601\Model\VariantAttributeDeleteResponse';
        $request = $this->deleteVariantAttributeRequest($attribute_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 'deleteVariantAttribute'
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to delete. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteVariantAttribute'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function deleteVariantAttributeRequest($attribute_id, string $contentType = self::contentTypes['deleteVariantAttribute'][0])
    {

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


        $resourcePath = '/variant_attributes/{attribute-id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($attribute_id !== null) {
            $resourcePath = str_replace(
                '{' . 'attribute-id' . '}',
                ObjectSerializer::toPathValue($attribute_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(
            'DELETE',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getVariantAttributes
     *
     * Retrieve a single Variant Attribute
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to retrieve. (required)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getVariantAttributes'] 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\VariantAttributeResponse
     */
    public function getVariantAttributes($attribute_id, $deleted = null, string $contentType = self::contentTypes['getVariantAttributes'][0])
    {
        list($response) = $this->getVariantAttributesWithHttpInfo($attribute_id, $deleted, $contentType);
        return $response;
    }

    /**
     * Operation getVariantAttributesWithHttpInfo
     *
     * Retrieve a single Variant Attribute
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to retrieve. (required)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getVariantAttributes'] 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\VariantAttributeResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getVariantAttributesWithHttpInfo($attribute_id, $deleted = null, string $contentType = self::contentTypes['getVariantAttributes'][0])
    {
        $request = $this->getVariantAttributesRequest($attribute_id, $deleted, $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\VariantAttributeResponse',
                        $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\VariantAttributeResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\VariantAttributeResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getVariantAttributesAsync
     *
     * Retrieve a single Variant Attribute
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to retrieve. (required)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getVariantAttributes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getVariantAttributesAsync($attribute_id, $deleted = null, string $contentType = self::contentTypes['getVariantAttributes'][0])
    {
        return $this->getVariantAttributesAsyncWithHttpInfo($attribute_id, $deleted, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getVariantAttributesAsyncWithHttpInfo
     *
     * Retrieve a single Variant Attribute
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to retrieve. (required)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getVariantAttributes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getVariantAttributesAsyncWithHttpInfo($attribute_id, $deleted = null, string $contentType = self::contentTypes['getVariantAttributes'][0])
    {
        $returnType = '\Vend202601\Model\VariantAttributeResponse';
        $request = $this->getVariantAttributesRequest($attribute_id, $deleted, $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 'getVariantAttributes'
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to retrieve. (required)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getVariantAttributes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getVariantAttributesRequest($attribute_id, $deleted = null, string $contentType = self::contentTypes['getVariantAttributes'][0])
    {

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



        $resourcePath = '/variant_attributes/{attribute-id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $deleted,
            'deleted', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);


        // path params
        if ($attribute_id !== null) {
            $resourcePath = str_replace(
                '{' . 'attribute-id' . '}',
                ObjectSerializer::toPathValue($attribute_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 listVariantAttributes
     *
     * Retrieve all Variant Attributes
     *
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listVariantAttributes'] 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\VariantAttributesListResponse
     */
    public function listVariantAttributes($deleted = null, string $contentType = self::contentTypes['listVariantAttributes'][0])
    {
        list($response) = $this->listVariantAttributesWithHttpInfo($deleted, $contentType);
        return $response;
    }

    /**
     * Operation listVariantAttributesWithHttpInfo
     *
     * Retrieve all Variant Attributes
     *
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listVariantAttributes'] 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\VariantAttributesListResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function listVariantAttributesWithHttpInfo($deleted = null, string $contentType = self::contentTypes['listVariantAttributes'][0])
    {
        $request = $this->listVariantAttributesRequest($deleted, $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\VariantAttributesListResponse',
                        $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\VariantAttributesListResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\VariantAttributesListResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation listVariantAttributesAsync
     *
     * Retrieve all Variant Attributes
     *
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listVariantAttributes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listVariantAttributesAsync($deleted = null, string $contentType = self::contentTypes['listVariantAttributes'][0])
    {
        return $this->listVariantAttributesAsyncWithHttpInfo($deleted, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation listVariantAttributesAsyncWithHttpInfo
     *
     * Retrieve all Variant Attributes
     *
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listVariantAttributes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listVariantAttributesAsyncWithHttpInfo($deleted = null, string $contentType = self::contentTypes['listVariantAttributes'][0])
    {
        $returnType = '\Vend202601\Model\VariantAttributesListResponse';
        $request = $this->listVariantAttributesRequest($deleted, $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 'listVariantAttributes'
     *
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listVariantAttributes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function listVariantAttributesRequest($deleted = null, string $contentType = self::contentTypes['listVariantAttributes'][0])
    {



        $resourcePath = '/variant_attributes';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $deleted,
            'deleted', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);




        $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 updateVariantAttribute
     *
     * Update a Variant Attribute&#39;s
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to update. (required)
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateVariantAttribute'] 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\VariantAttributeUpdateResponse|object|object
     */
    public function updateVariantAttribute($attribute_id, $variant_attribute_create_update_body, string $contentType = self::contentTypes['updateVariantAttribute'][0])
    {
        list($response) = $this->updateVariantAttributeWithHttpInfo($attribute_id, $variant_attribute_create_update_body, $contentType);
        return $response;
    }

    /**
     * Operation updateVariantAttributeWithHttpInfo
     *
     * Update a Variant Attribute&#39;s
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to update. (required)
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateVariantAttribute'] 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\VariantAttributeUpdateResponse|object|object, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateVariantAttributeWithHttpInfo($attribute_id, $variant_attribute_create_update_body, string $contentType = self::contentTypes['updateVariantAttribute'][0])
    {
        $request = $this->updateVariantAttributeRequest($attribute_id, $variant_attribute_create_update_body, $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\VariantAttributeUpdateResponse',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        'object',
                        $request,
                        $response,
                    );
                case 422:
                    return $this->handleResponseWithDataType(
                        'object',
                        $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\VariantAttributeUpdateResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\VariantAttributeUpdateResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'object',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 422:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'object',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation updateVariantAttributeAsync
     *
     * Update a Variant Attribute&#39;s
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to update. (required)
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateVariantAttribute'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateVariantAttributeAsync($attribute_id, $variant_attribute_create_update_body, string $contentType = self::contentTypes['updateVariantAttribute'][0])
    {
        return $this->updateVariantAttributeAsyncWithHttpInfo($attribute_id, $variant_attribute_create_update_body, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateVariantAttributeAsyncWithHttpInfo
     *
     * Update a Variant Attribute&#39;s
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to update. (required)
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateVariantAttribute'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateVariantAttributeAsyncWithHttpInfo($attribute_id, $variant_attribute_create_update_body, string $contentType = self::contentTypes['updateVariantAttribute'][0])
    {
        $returnType = '\Vend202601\Model\VariantAttributeUpdateResponse';
        $request = $this->updateVariantAttributeRequest($attribute_id, $variant_attribute_create_update_body, $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 'updateVariantAttribute'
     *
     * @param  string $attribute_id The object identifier of the Variant Attribute to update. (required)
     * @param  \Vend202601\Model\VariantAttributeCreateUpdateBody $variant_attribute_create_update_body (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateVariantAttribute'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updateVariantAttributeRequest($attribute_id, $variant_attribute_create_update_body, string $contentType = self::contentTypes['updateVariantAttribute'][0])
    {

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

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


        $resourcePath = '/variant_attributes/{attribute-id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

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