<?php
/**
 * PromotionsApi
 * 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;

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'applyDiscount' => [
            'application/json',
        ],
        'createPromotion' => [
            'application/json',
        ],
        'getPromotionByID' => [
            'application/json',
        ],
        'getPromotionProducts' => [
            'application/json',
        ],
        'getPromotionPromoCodes' => [
            'application/json',
        ],
        'listPromotions' => [
            'application/json',
        ],
        'searchPromotions' => [
            'application/json',
        ],
        'updatePromotion' => [
            '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 applyDiscount
     *
     * Apply discounts to a sale object
     *
     * @param  \Vend202601\Model\DiscountParam $discount_param discount_param (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['applyDiscount'] 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\DiscountResponse
     */
    public function applyDiscount($discount_param, string $contentType = self::contentTypes['applyDiscount'][0])
    {
        list($response) = $this->applyDiscountWithHttpInfo($discount_param, $contentType);
        return $response;
    }

    /**
     * Operation applyDiscountWithHttpInfo
     *
     * Apply discounts to a sale object
     *
     * @param  \Vend202601\Model\DiscountParam $discount_param (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['applyDiscount'] 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\DiscountResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function applyDiscountWithHttpInfo($discount_param, string $contentType = self::contentTypes['applyDiscount'][0])
    {
        $request = $this->applyDiscountRequest($discount_param, $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\DiscountResponse',
                        $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\DiscountResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\DiscountResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation applyDiscountAsync
     *
     * Apply discounts to a sale object
     *
     * @param  \Vend202601\Model\DiscountParam $discount_param (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['applyDiscount'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function applyDiscountAsync($discount_param, string $contentType = self::contentTypes['applyDiscount'][0])
    {
        return $this->applyDiscountAsyncWithHttpInfo($discount_param, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation applyDiscountAsyncWithHttpInfo
     *
     * Apply discounts to a sale object
     *
     * @param  \Vend202601\Model\DiscountParam $discount_param (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['applyDiscount'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function applyDiscountAsyncWithHttpInfo($discount_param, string $contentType = self::contentTypes['applyDiscount'][0])
    {
        $returnType = '\Vend202601\Model\DiscountResponse';
        $request = $this->applyDiscountRequest($discount_param, $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 'applyDiscount'
     *
     * @param  \Vend202601\Model\DiscountParam $discount_param (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['applyDiscount'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function applyDiscountRequest($discount_param, string $contentType = self::contentTypes['applyDiscount'][0])
    {

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


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





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

        // for model (json/xml)
        if (isset($discount_param)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($discount_param));
            } else {
                $httpBody = $discount_param;
            }
        } 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 createPromotion
     *
     * Create a promotion
     *
     * @param  \Vend202601\Model\Promotion $promotion promotion (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createPromotion'] 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\PromotionResponse
     */
    public function createPromotion($promotion, string $contentType = self::contentTypes['createPromotion'][0])
    {
        list($response) = $this->createPromotionWithHttpInfo($promotion, $contentType);
        return $response;
    }

    /**
     * Operation createPromotionWithHttpInfo
     *
     * Create a promotion
     *
     * @param  \Vend202601\Model\Promotion $promotion (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createPromotion'] 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\PromotionResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function createPromotionWithHttpInfo($promotion, string $contentType = self::contentTypes['createPromotion'][0])
    {
        $request = $this->createPromotionRequest($promotion, $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\PromotionResponse',
                        $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\PromotionResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PromotionResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

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

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

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


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





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

        // for model (json/xml)
        if (isset($promotion)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($promotion));
            } else {
                $httpBody = $promotion;
            }
        } 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 getPromotionByID
     *
     * Get a promotion by ID
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionByID'] 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\PromotionResponse
     */
    public function getPromotionByID($promotion_id, string $contentType = self::contentTypes['getPromotionByID'][0])
    {
        list($response) = $this->getPromotionByIDWithHttpInfo($promotion_id, $contentType);
        return $response;
    }

    /**
     * Operation getPromotionByIDWithHttpInfo
     *
     * Get a promotion by ID
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionByID'] 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\PromotionResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getPromotionByIDWithHttpInfo($promotion_id, string $contentType = self::contentTypes['getPromotionByID'][0])
    {
        $request = $this->getPromotionByIDRequest($promotion_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\PromotionResponse',
                        $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\PromotionResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PromotionResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getPromotionByIDAsync
     *
     * Get a promotion by ID
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionByID'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getPromotionByIDAsync($promotion_id, string $contentType = self::contentTypes['getPromotionByID'][0])
    {
        return $this->getPromotionByIDAsyncWithHttpInfo($promotion_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getPromotionByIDAsyncWithHttpInfo
     *
     * Get a promotion by ID
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionByID'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getPromotionByIDAsyncWithHttpInfo($promotion_id, string $contentType = self::contentTypes['getPromotionByID'][0])
    {
        $returnType = '\Vend202601\Model\PromotionResponse';
        $request = $this->getPromotionByIDRequest($promotion_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 'getPromotionByID'
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionByID'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getPromotionByIDRequest($promotion_id, string $contentType = self::contentTypes['getPromotionByID'][0])
    {

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


        $resourcePath = '/promotions/{promotion_id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($promotion_id !== null) {
            $resourcePath = str_replace(
                '{' . 'promotion_id' . '}',
                ObjectSerializer::toPathValue($promotion_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 getPromotionProducts
     *
     * Get products for a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionProducts'] 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\PromotionProductsResponse
     */
    public function getPromotionProducts($promotion_id, string $contentType = self::contentTypes['getPromotionProducts'][0])
    {
        list($response) = $this->getPromotionProductsWithHttpInfo($promotion_id, $contentType);
        return $response;
    }

    /**
     * Operation getPromotionProductsWithHttpInfo
     *
     * Get products for a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionProducts'] 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\PromotionProductsResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getPromotionProductsWithHttpInfo($promotion_id, string $contentType = self::contentTypes['getPromotionProducts'][0])
    {
        $request = $this->getPromotionProductsRequest($promotion_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\PromotionProductsResponse',
                        $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\PromotionProductsResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PromotionProductsResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

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

    /**
     * Operation getPromotionProductsAsyncWithHttpInfo
     *
     * Get products for a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionProducts'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getPromotionProductsAsyncWithHttpInfo($promotion_id, string $contentType = self::contentTypes['getPromotionProducts'][0])
    {
        $returnType = '\Vend202601\Model\PromotionProductsResponse';
        $request = $this->getPromotionProductsRequest($promotion_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 'getPromotionProducts'
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionProducts'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getPromotionProductsRequest($promotion_id, string $contentType = self::contentTypes['getPromotionProducts'][0])
    {

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


        $resourcePath = '/promotions/{promotion_id}/products';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($promotion_id !== null) {
            $resourcePath = str_replace(
                '{' . 'promotion_id' . '}',
                ObjectSerializer::toPathValue($promotion_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 getPromotionPromoCodes
     *
     * Get the promo codes for a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionPromoCodes'] 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\PromotionPromoCodesResponse
     */
    public function getPromotionPromoCodes($promotion_id, string $contentType = self::contentTypes['getPromotionPromoCodes'][0])
    {
        list($response) = $this->getPromotionPromoCodesWithHttpInfo($promotion_id, $contentType);
        return $response;
    }

    /**
     * Operation getPromotionPromoCodesWithHttpInfo
     *
     * Get the promo codes for a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionPromoCodes'] 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\PromotionPromoCodesResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getPromotionPromoCodesWithHttpInfo($promotion_id, string $contentType = self::contentTypes['getPromotionPromoCodes'][0])
    {
        $request = $this->getPromotionPromoCodesRequest($promotion_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\PromotionPromoCodesResponse',
                        $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\PromotionPromoCodesResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PromotionPromoCodesResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getPromotionPromoCodesAsync
     *
     * Get the promo codes for a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionPromoCodes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getPromotionPromoCodesAsync($promotion_id, string $contentType = self::contentTypes['getPromotionPromoCodes'][0])
    {
        return $this->getPromotionPromoCodesAsyncWithHttpInfo($promotion_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getPromotionPromoCodesAsyncWithHttpInfo
     *
     * Get the promo codes for a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionPromoCodes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getPromotionPromoCodesAsyncWithHttpInfo($promotion_id, string $contentType = self::contentTypes['getPromotionPromoCodes'][0])
    {
        $returnType = '\Vend202601\Model\PromotionPromoCodesResponse';
        $request = $this->getPromotionPromoCodesRequest($promotion_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 'getPromotionPromoCodes'
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getPromotionPromoCodes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getPromotionPromoCodesRequest($promotion_id, string $contentType = self::contentTypes['getPromotionPromoCodes'][0])
    {

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


        $resourcePath = '/promotions/{promotion_id}/promocodes';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($promotion_id !== null) {
            $resourcePath = str_replace(
                '{' . 'promotion_id' . '}',
                ObjectSerializer::toPathValue($promotion_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 listPromotions
     *
     * List promotions
     *
     * @param  string|null $end_time_to Upper limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  string|null $end_time_from Lower limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listPromotions'] 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\PromotionCollection
     */
    public function listPromotions($end_time_to = null, $end_time_from = null, $page_size = null, string $contentType = self::contentTypes['listPromotions'][0])
    {
        list($response) = $this->listPromotionsWithHttpInfo($end_time_to, $end_time_from, $page_size, $contentType);
        return $response;
    }

    /**
     * Operation listPromotionsWithHttpInfo
     *
     * List promotions
     *
     * @param  string|null $end_time_to Upper limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  string|null $end_time_from Lower limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listPromotions'] 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\PromotionCollection, HTTP status code, HTTP response headers (array of strings)
     */
    public function listPromotionsWithHttpInfo($end_time_to = null, $end_time_from = null, $page_size = null, string $contentType = self::contentTypes['listPromotions'][0])
    {
        $request = $this->listPromotionsRequest($end_time_to, $end_time_from, $page_size, $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\PromotionCollection',
                        $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\PromotionCollection',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PromotionCollection',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation listPromotionsAsync
     *
     * List promotions
     *
     * @param  string|null $end_time_to Upper limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  string|null $end_time_from Lower limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listPromotions'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listPromotionsAsync($end_time_to = null, $end_time_from = null, $page_size = null, string $contentType = self::contentTypes['listPromotions'][0])
    {
        return $this->listPromotionsAsyncWithHttpInfo($end_time_to, $end_time_from, $page_size, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation listPromotionsAsyncWithHttpInfo
     *
     * List promotions
     *
     * @param  string|null $end_time_to Upper limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  string|null $end_time_from Lower limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listPromotions'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listPromotionsAsyncWithHttpInfo($end_time_to = null, $end_time_from = null, $page_size = null, string $contentType = self::contentTypes['listPromotions'][0])
    {
        $returnType = '\Vend202601\Model\PromotionCollection';
        $request = $this->listPromotionsRequest($end_time_to, $end_time_from, $page_size, $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 'listPromotions'
     *
     * @param  string|null $end_time_to Upper limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  string|null $end_time_from Lower limit for the promotion end date as UTC timestamp. Format: &#x60;2020-08-08T12:00:00Z&#x60;. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listPromotions'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function listPromotionsRequest($end_time_to = null, $end_time_from = null, $page_size = null, string $contentType = self::contentTypes['listPromotions'][0])
    {





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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $end_time_to,
            'end_time_to', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $end_time_from,
            'end_time_from', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page_size,
            'page_size', // param base name
            'integer', // 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 searchPromotions
     *
     * Search promotions
     *
     * @param  string|null $scope Scope of the search (optional, default to 'all')
     * @param  string|null $name Part of promotion&#39;s name being searched (optional)
     * @param  string|null $start_time Only show promotions that have a start time after or equal to this (optional)
     * @param  string|null $end_time Only show promotions that have an end time before or equal to this (optional)
     * @param  string[]|null $outlet_id Only show promotions linked to one or many of the outlets specified here (optional)
     * @param  string|null $order_by Sort the result by this field (optional, default to 'name')
     * @param  string|null $direction Sort direction (optional, default to 'desc')
     * @param  int|null $offset Offset (optional, default to 1)
     * @param  int|null $page_size Number of results per page (optional, default to 1000)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['searchPromotions'] 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\PromotionCollection
     */
    public function searchPromotions($scope = 'all', $name = null, $start_time = null, $end_time = null, $outlet_id = null, $order_by = 'name', $direction = 'desc', $offset = 1, $page_size = 1000, string $contentType = self::contentTypes['searchPromotions'][0])
    {
        list($response) = $this->searchPromotionsWithHttpInfo($scope, $name, $start_time, $end_time, $outlet_id, $order_by, $direction, $offset, $page_size, $contentType);
        return $response;
    }

    /**
     * Operation searchPromotionsWithHttpInfo
     *
     * Search promotions
     *
     * @param  string|null $scope Scope of the search (optional, default to 'all')
     * @param  string|null $name Part of promotion&#39;s name being searched (optional)
     * @param  string|null $start_time Only show promotions that have a start time after or equal to this (optional)
     * @param  string|null $end_time Only show promotions that have an end time before or equal to this (optional)
     * @param  string[]|null $outlet_id Only show promotions linked to one or many of the outlets specified here (optional)
     * @param  string|null $order_by Sort the result by this field (optional, default to 'name')
     * @param  string|null $direction Sort direction (optional, default to 'desc')
     * @param  int|null $offset Offset (optional, default to 1)
     * @param  int|null $page_size Number of results per page (optional, default to 1000)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['searchPromotions'] 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\PromotionCollection, HTTP status code, HTTP response headers (array of strings)
     */
    public function searchPromotionsWithHttpInfo($scope = 'all', $name = null, $start_time = null, $end_time = null, $outlet_id = null, $order_by = 'name', $direction = 'desc', $offset = 1, $page_size = 1000, string $contentType = self::contentTypes['searchPromotions'][0])
    {
        $request = $this->searchPromotionsRequest($scope, $name, $start_time, $end_time, $outlet_id, $order_by, $direction, $offset, $page_size, $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\PromotionCollection',
                        $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\PromotionCollection',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PromotionCollection',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation searchPromotionsAsync
     *
     * Search promotions
     *
     * @param  string|null $scope Scope of the search (optional, default to 'all')
     * @param  string|null $name Part of promotion&#39;s name being searched (optional)
     * @param  string|null $start_time Only show promotions that have a start time after or equal to this (optional)
     * @param  string|null $end_time Only show promotions that have an end time before or equal to this (optional)
     * @param  string[]|null $outlet_id Only show promotions linked to one or many of the outlets specified here (optional)
     * @param  string|null $order_by Sort the result by this field (optional, default to 'name')
     * @param  string|null $direction Sort direction (optional, default to 'desc')
     * @param  int|null $offset Offset (optional, default to 1)
     * @param  int|null $page_size Number of results per page (optional, default to 1000)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['searchPromotions'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function searchPromotionsAsync($scope = 'all', $name = null, $start_time = null, $end_time = null, $outlet_id = null, $order_by = 'name', $direction = 'desc', $offset = 1, $page_size = 1000, string $contentType = self::contentTypes['searchPromotions'][0])
    {
        return $this->searchPromotionsAsyncWithHttpInfo($scope, $name, $start_time, $end_time, $outlet_id, $order_by, $direction, $offset, $page_size, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation searchPromotionsAsyncWithHttpInfo
     *
     * Search promotions
     *
     * @param  string|null $scope Scope of the search (optional, default to 'all')
     * @param  string|null $name Part of promotion&#39;s name being searched (optional)
     * @param  string|null $start_time Only show promotions that have a start time after or equal to this (optional)
     * @param  string|null $end_time Only show promotions that have an end time before or equal to this (optional)
     * @param  string[]|null $outlet_id Only show promotions linked to one or many of the outlets specified here (optional)
     * @param  string|null $order_by Sort the result by this field (optional, default to 'name')
     * @param  string|null $direction Sort direction (optional, default to 'desc')
     * @param  int|null $offset Offset (optional, default to 1)
     * @param  int|null $page_size Number of results per page (optional, default to 1000)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['searchPromotions'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function searchPromotionsAsyncWithHttpInfo($scope = 'all', $name = null, $start_time = null, $end_time = null, $outlet_id = null, $order_by = 'name', $direction = 'desc', $offset = 1, $page_size = 1000, string $contentType = self::contentTypes['searchPromotions'][0])
    {
        $returnType = '\Vend202601\Model\PromotionCollection';
        $request = $this->searchPromotionsRequest($scope, $name, $start_time, $end_time, $outlet_id, $order_by, $direction, $offset, $page_size, $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 'searchPromotions'
     *
     * @param  string|null $scope Scope of the search (optional, default to 'all')
     * @param  string|null $name Part of promotion&#39;s name being searched (optional)
     * @param  string|null $start_time Only show promotions that have a start time after or equal to this (optional)
     * @param  string|null $end_time Only show promotions that have an end time before or equal to this (optional)
     * @param  string[]|null $outlet_id Only show promotions linked to one or many of the outlets specified here (optional)
     * @param  string|null $order_by Sort the result by this field (optional, default to 'name')
     * @param  string|null $direction Sort direction (optional, default to 'desc')
     * @param  int|null $offset Offset (optional, default to 1)
     * @param  int|null $page_size Number of results per page (optional, default to 1000)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['searchPromotions'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function searchPromotionsRequest($scope = 'all', $name = null, $start_time = null, $end_time = null, $outlet_id = null, $order_by = 'name', $direction = 'desc', $offset = 1, $page_size = 1000, string $contentType = self::contentTypes['searchPromotions'][0])
    {











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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $scope,
            'scope', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $name,
            'name', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $start_time,
            'start_time', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $end_time,
            'end_time', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $outlet_id,
            'outlet_id', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $order_by,
            'order_by', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $direction,
            'direction', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $offset,
            'offset', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page_size,
            'page_size', // param base name
            'integer', // 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 updatePromotion
     *
     * Update a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  \Vend202601\Model\Promotion $promotion promotion (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePromotion'] 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\PromotionResponse
     */
    public function updatePromotion($promotion_id, $promotion, string $contentType = self::contentTypes['updatePromotion'][0])
    {
        list($response) = $this->updatePromotionWithHttpInfo($promotion_id, $promotion, $contentType);
        return $response;
    }

    /**
     * Operation updatePromotionWithHttpInfo
     *
     * Update a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  \Vend202601\Model\Promotion $promotion (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePromotion'] 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\PromotionResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function updatePromotionWithHttpInfo($promotion_id, $promotion, string $contentType = self::contentTypes['updatePromotion'][0])
    {
        $request = $this->updatePromotionRequest($promotion_id, $promotion, $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\PromotionResponse',
                        $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\PromotionResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\PromotionResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation updatePromotionAsync
     *
     * Update a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  \Vend202601\Model\Promotion $promotion (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePromotion'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updatePromotionAsync($promotion_id, $promotion, string $contentType = self::contentTypes['updatePromotion'][0])
    {
        return $this->updatePromotionAsyncWithHttpInfo($promotion_id, $promotion, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updatePromotionAsyncWithHttpInfo
     *
     * Update a promotion
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  \Vend202601\Model\Promotion $promotion (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePromotion'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updatePromotionAsyncWithHttpInfo($promotion_id, $promotion, string $contentType = self::contentTypes['updatePromotion'][0])
    {
        $returnType = '\Vend202601\Model\PromotionResponse';
        $request = $this->updatePromotionRequest($promotion_id, $promotion, $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 'updatePromotion'
     *
     * @param  string $promotion_id The promotion id (required)
     * @param  \Vend202601\Model\Promotion $promotion (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePromotion'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updatePromotionRequest($promotion_id, $promotion, string $contentType = self::contentTypes['updatePromotion'][0])
    {

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

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


        $resourcePath = '/promotions/{promotion_id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

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