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

/**
 * API 2026-01
 *
 * Lightspeed Retail (X-Series) API.
 *
 * The version of the OpenAPI document: 2026-01
 * Contact: x-series.api@lightspeedhq.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.20.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace Vend202601\Api;

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

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'addCustomersToCustomerGroup' => [
            'application/json',
        ],
        'createCustomerGroup' => [
            'application/json',
        ],
        'deleteCustomersFromCustomerGroup' => [
            'application/json',
        ],
        'getCustomerGroupById' => [
            'application/json',
        ],
        'getCustomerGroupCustomers' => [
            'application/json',
        ],
        'listCustomerGroups' => [
            'application/json',
        ],
        'updateCustomerGroup' => [
            '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 addCustomersToCustomerGroup
     *
     * Add customers to customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\AddCustomersToCustomerGroupRequest $add_customers_to_customer_group_request add_customers_to_customer_group_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addCustomersToCustomerGroup'] 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 bool
     */
    public function addCustomersToCustomerGroup($customer_group_id, $add_customers_to_customer_group_request, string $contentType = self::contentTypes['addCustomersToCustomerGroup'][0])
    {
        list($response) = $this->addCustomersToCustomerGroupWithHttpInfo($customer_group_id, $add_customers_to_customer_group_request, $contentType);
        return $response;
    }

    /**
     * Operation addCustomersToCustomerGroupWithHttpInfo
     *
     * Add customers to customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\AddCustomersToCustomerGroupRequest $add_customers_to_customer_group_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addCustomersToCustomerGroup'] 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 bool, HTTP status code, HTTP response headers (array of strings)
     */
    public function addCustomersToCustomerGroupWithHttpInfo($customer_group_id, $add_customers_to_customer_group_request, string $contentType = self::contentTypes['addCustomersToCustomerGroup'][0])
    {
        $request = $this->addCustomersToCustomerGroupRequest($customer_group_id, $add_customers_to_customer_group_request, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 201:
                    return $this->handleResponseWithDataType(
                        'bool',
                        $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(
                'bool',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'bool',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation addCustomersToCustomerGroupAsync
     *
     * Add customers to customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\AddCustomersToCustomerGroupRequest $add_customers_to_customer_group_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addCustomersToCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function addCustomersToCustomerGroupAsync($customer_group_id, $add_customers_to_customer_group_request, string $contentType = self::contentTypes['addCustomersToCustomerGroup'][0])
    {
        return $this->addCustomersToCustomerGroupAsyncWithHttpInfo($customer_group_id, $add_customers_to_customer_group_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation addCustomersToCustomerGroupAsyncWithHttpInfo
     *
     * Add customers to customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\AddCustomersToCustomerGroupRequest $add_customers_to_customer_group_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addCustomersToCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function addCustomersToCustomerGroupAsyncWithHttpInfo($customer_group_id, $add_customers_to_customer_group_request, string $contentType = self::contentTypes['addCustomersToCustomerGroup'][0])
    {
        $returnType = 'bool';
        $request = $this->addCustomersToCustomerGroupRequest($customer_group_id, $add_customers_to_customer_group_request, $contentType);

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

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

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

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

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


        $resourcePath = '/customer_groups/{customer_group_id}/customers';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

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

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

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

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

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

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

    /**
     * Operation createCustomerGroup
     *
     * Create new customer group
     *
     * @param  \Vend202601\Model\CustomerGroup $customer_group customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createCustomerGroup'] 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\CustomerGroupResponse
     */
    public function createCustomerGroup($customer_group, string $contentType = self::contentTypes['createCustomerGroup'][0])
    {
        list($response) = $this->createCustomerGroupWithHttpInfo($customer_group, $contentType);
        return $response;
    }

    /**
     * Operation createCustomerGroupWithHttpInfo
     *
     * Create new customer group
     *
     * @param  \Vend202601\Model\CustomerGroup $customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createCustomerGroup'] 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\CustomerGroupResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function createCustomerGroupWithHttpInfo($customer_group, string $contentType = self::contentTypes['createCustomerGroup'][0])
    {
        $request = $this->createCustomerGroupRequest($customer_group, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 201:
                    return $this->handleResponseWithDataType(
                        '\Vend202601\Model\CustomerGroupResponse',
                        $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\CustomerGroupResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\CustomerGroupResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation createCustomerGroupAsync
     *
     * Create new customer group
     *
     * @param  \Vend202601\Model\CustomerGroup $customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCustomerGroupAsync($customer_group, string $contentType = self::contentTypes['createCustomerGroup'][0])
    {
        return $this->createCustomerGroupAsyncWithHttpInfo($customer_group, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation createCustomerGroupAsyncWithHttpInfo
     *
     * Create new customer group
     *
     * @param  \Vend202601\Model\CustomerGroup $customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCustomerGroupAsyncWithHttpInfo($customer_group, string $contentType = self::contentTypes['createCustomerGroup'][0])
    {
        $returnType = '\Vend202601\Model\CustomerGroupResponse';
        $request = $this->createCustomerGroupRequest($customer_group, $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 'createCustomerGroup'
     *
     * @param  \Vend202601\Model\CustomerGroup $customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['createCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function createCustomerGroupRequest($customer_group, string $contentType = self::contentTypes['createCustomerGroup'][0])
    {

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


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





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

        // for model (json/xml)
        if (isset($customer_group)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($customer_group));
            } else {
                $httpBody = $customer_group;
            }
        } 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 deleteCustomersFromCustomerGroup
     *
     * Delete customers from customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\DeleteCustomersFromCustomerGroupRequest $delete_customers_from_customer_group_request delete_customers_from_customer_group_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteCustomersFromCustomerGroup'] 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 string
     */
    public function deleteCustomersFromCustomerGroup($customer_group_id, $delete_customers_from_customer_group_request, string $contentType = self::contentTypes['deleteCustomersFromCustomerGroup'][0])
    {
        list($response) = $this->deleteCustomersFromCustomerGroupWithHttpInfo($customer_group_id, $delete_customers_from_customer_group_request, $contentType);
        return $response;
    }

    /**
     * Operation deleteCustomersFromCustomerGroupWithHttpInfo
     *
     * Delete customers from customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\DeleteCustomersFromCustomerGroupRequest $delete_customers_from_customer_group_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteCustomersFromCustomerGroup'] 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 string, HTTP status code, HTTP response headers (array of strings)
     */
    public function deleteCustomersFromCustomerGroupWithHttpInfo($customer_group_id, $delete_customers_from_customer_group_request, string $contentType = self::contentTypes['deleteCustomersFromCustomerGroup'][0])
    {
        $request = $this->deleteCustomersFromCustomerGroupRequest($customer_group_id, $delete_customers_from_customer_group_request, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 204:
                    return $this->handleResponseWithDataType(
                        'string',
                        $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(
                'string',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 204:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'string',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation deleteCustomersFromCustomerGroupAsync
     *
     * Delete customers from customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\DeleteCustomersFromCustomerGroupRequest $delete_customers_from_customer_group_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteCustomersFromCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteCustomersFromCustomerGroupAsync($customer_group_id, $delete_customers_from_customer_group_request, string $contentType = self::contentTypes['deleteCustomersFromCustomerGroup'][0])
    {
        return $this->deleteCustomersFromCustomerGroupAsyncWithHttpInfo($customer_group_id, $delete_customers_from_customer_group_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteCustomersFromCustomerGroupAsyncWithHttpInfo
     *
     * Delete customers from customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\DeleteCustomersFromCustomerGroupRequest $delete_customers_from_customer_group_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteCustomersFromCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteCustomersFromCustomerGroupAsyncWithHttpInfo($customer_group_id, $delete_customers_from_customer_group_request, string $contentType = self::contentTypes['deleteCustomersFromCustomerGroup'][0])
    {
        $returnType = 'string';
        $request = $this->deleteCustomersFromCustomerGroupRequest($customer_group_id, $delete_customers_from_customer_group_request, $contentType);

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

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

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

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

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


        $resourcePath = '/customer_groups/{customer_group_id}/customers';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

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

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

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

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

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

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

    /**
     * Operation getCustomerGroupById
     *
     * Get single customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCustomerGroupById'] 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\CustomerGroupResponse
     */
    public function getCustomerGroupById($customer_group_id, string $contentType = self::contentTypes['getCustomerGroupById'][0])
    {
        list($response) = $this->getCustomerGroupByIdWithHttpInfo($customer_group_id, $contentType);
        return $response;
    }

    /**
     * Operation getCustomerGroupByIdWithHttpInfo
     *
     * Get single customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCustomerGroupById'] 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\CustomerGroupResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCustomerGroupByIdWithHttpInfo($customer_group_id, string $contentType = self::contentTypes['getCustomerGroupById'][0])
    {
        $request = $this->getCustomerGroupByIdRequest($customer_group_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\CustomerGroupResponse',
                        $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\CustomerGroupResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\CustomerGroupResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getCustomerGroupByIdAsync
     *
     * Get single customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCustomerGroupById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCustomerGroupByIdAsync($customer_group_id, string $contentType = self::contentTypes['getCustomerGroupById'][0])
    {
        return $this->getCustomerGroupByIdAsyncWithHttpInfo($customer_group_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCustomerGroupByIdAsyncWithHttpInfo
     *
     * Get single customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCustomerGroupById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCustomerGroupByIdAsyncWithHttpInfo($customer_group_id, string $contentType = self::contentTypes['getCustomerGroupById'][0])
    {
        $returnType = '\Vend202601\Model\CustomerGroupResponse';
        $request = $this->getCustomerGroupByIdRequest($customer_group_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 'getCustomerGroupById'
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCustomerGroupById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCustomerGroupByIdRequest($customer_group_id, string $contentType = self::contentTypes['getCustomerGroupById'][0])
    {

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


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



        // path params
        if ($customer_group_id !== null) {
            $resourcePath = str_replace(
                '{' . 'customer_group_id' . '}',
                ObjectSerializer::toPathValue($customer_group_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 getCustomerGroupCustomers
     *
     * Get customers for customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (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['getCustomerGroupCustomers'] 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\CustomerCollection
     */
    public function getCustomerGroupCustomers($customer_group_id, $after = null, $before = null, $page_size = null, string $contentType = self::contentTypes['getCustomerGroupCustomers'][0])
    {
        list($response) = $this->getCustomerGroupCustomersWithHttpInfo($customer_group_id, $after, $before, $page_size, $contentType);
        return $response;
    }

    /**
     * Operation getCustomerGroupCustomersWithHttpInfo
     *
     * Get customers for customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (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['getCustomerGroupCustomers'] 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\CustomerCollection, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCustomerGroupCustomersWithHttpInfo($customer_group_id, $after = null, $before = null, $page_size = null, string $contentType = self::contentTypes['getCustomerGroupCustomers'][0])
    {
        $request = $this->getCustomerGroupCustomersRequest($customer_group_id, $after, $before, $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\CustomerCollection',
                        $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\CustomerCollection',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\CustomerCollection',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getCustomerGroupCustomersAsync
     *
     * Get customers for customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (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['getCustomerGroupCustomers'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCustomerGroupCustomersAsync($customer_group_id, $after = null, $before = null, $page_size = null, string $contentType = self::contentTypes['getCustomerGroupCustomers'][0])
    {
        return $this->getCustomerGroupCustomersAsyncWithHttpInfo($customer_group_id, $after, $before, $page_size, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCustomerGroupCustomersAsyncWithHttpInfo
     *
     * Get customers for customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (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['getCustomerGroupCustomers'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCustomerGroupCustomersAsyncWithHttpInfo($customer_group_id, $after = null, $before = null, $page_size = null, string $contentType = self::contentTypes['getCustomerGroupCustomers'][0])
    {
        $returnType = '\Vend202601\Model\CustomerCollection';
        $request = $this->getCustomerGroupCustomersRequest($customer_group_id, $after, $before, $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 'getCustomerGroupCustomers'
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (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['getCustomerGroupCustomers'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCustomerGroupCustomersRequest($customer_group_id, $after = null, $before = null, $page_size = null, string $contentType = self::contentTypes['getCustomerGroupCustomers'][0])
    {

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





        $resourcePath = '/customer_groups/{customer_group_id}/customers';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $after,
            'after', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $before,
            'before', // 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
        ) ?? []);


        // path params
        if ($customer_group_id !== null) {
            $resourcePath = str_replace(
                '{' . 'customer_group_id' . '}',
                ObjectSerializer::toPathValue($customer_group_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 listCustomerGroups
     *
     * List customer groups
     *
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listCustomerGroups'] 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\CustomerGroupCollection
     */
    public function listCustomerGroups($after = null, $before = null, $page_size = null, $deleted = null, string $contentType = self::contentTypes['listCustomerGroups'][0])
    {
        list($response) = $this->listCustomerGroupsWithHttpInfo($after, $before, $page_size, $deleted, $contentType);
        return $response;
    }

    /**
     * Operation listCustomerGroupsWithHttpInfo
     *
     * List customer groups
     *
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listCustomerGroups'] 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\CustomerGroupCollection, HTTP status code, HTTP response headers (array of strings)
     */
    public function listCustomerGroupsWithHttpInfo($after = null, $before = null, $page_size = null, $deleted = null, string $contentType = self::contentTypes['listCustomerGroups'][0])
    {
        $request = $this->listCustomerGroupsRequest($after, $before, $page_size, $deleted, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Vend202601\Model\CustomerGroupCollection',
                        $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\CustomerGroupCollection',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\CustomerGroupCollection',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation listCustomerGroupsAsync
     *
     * List customer groups
     *
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listCustomerGroups'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listCustomerGroupsAsync($after = null, $before = null, $page_size = null, $deleted = null, string $contentType = self::contentTypes['listCustomerGroups'][0])
    {
        return $this->listCustomerGroupsAsyncWithHttpInfo($after, $before, $page_size, $deleted, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation listCustomerGroupsAsyncWithHttpInfo
     *
     * List customer groups
     *
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listCustomerGroups'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listCustomerGroupsAsyncWithHttpInfo($after = null, $before = null, $page_size = null, $deleted = null, string $contentType = self::contentTypes['listCustomerGroups'][0])
    {
        $returnType = '\Vend202601\Model\CustomerGroupCollection';
        $request = $this->listCustomerGroupsRequest($after, $before, $page_size, $deleted, $contentType);

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

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

    /**
     * Create request for operation 'listCustomerGroups'
     *
     * @param  int|null $after The lower limit for the version numbers to be included in the response. (optional)
     * @param  int|null $before The upper limit for the version numbers to be included in the response. (optional)
     * @param  int|null $page_size The maximum number of items to be returned in the response. (optional)
     * @param  bool|null $deleted Indicates whether deleted items should be included in the response. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['listCustomerGroups'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function listCustomerGroupsRequest($after = null, $before = null, $page_size = null, $deleted = null, string $contentType = self::contentTypes['listCustomerGroups'][0])
    {






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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $after,
            'after', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $before,
            'before', // 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
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $deleted,
            'deleted', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);




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

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

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

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

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

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

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

    /**
     * Operation updateCustomerGroup
     *
     * Update the given customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\CustomerGroup $customer_group customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateCustomerGroup'] 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\CustomerGroupResponse
     */
    public function updateCustomerGroup($customer_group_id, $customer_group, string $contentType = self::contentTypes['updateCustomerGroup'][0])
    {
        list($response) = $this->updateCustomerGroupWithHttpInfo($customer_group_id, $customer_group, $contentType);
        return $response;
    }

    /**
     * Operation updateCustomerGroupWithHttpInfo
     *
     * Update the given customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\CustomerGroup $customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateCustomerGroup'] 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\CustomerGroupResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateCustomerGroupWithHttpInfo($customer_group_id, $customer_group, string $contentType = self::contentTypes['updateCustomerGroup'][0])
    {
        $request = $this->updateCustomerGroupRequest($customer_group_id, $customer_group, $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\CustomerGroupResponse',
                        $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\CustomerGroupResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend202601\Model\CustomerGroupResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation updateCustomerGroupAsync
     *
     * Update the given customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\CustomerGroup $customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCustomerGroupAsync($customer_group_id, $customer_group, string $contentType = self::contentTypes['updateCustomerGroup'][0])
    {
        return $this->updateCustomerGroupAsyncWithHttpInfo($customer_group_id, $customer_group, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateCustomerGroupAsyncWithHttpInfo
     *
     * Update the given customer group
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\CustomerGroup $customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCustomerGroupAsyncWithHttpInfo($customer_group_id, $customer_group, string $contentType = self::contentTypes['updateCustomerGroup'][0])
    {
        $returnType = '\Vend202601\Model\CustomerGroupResponse';
        $request = $this->updateCustomerGroupRequest($customer_group_id, $customer_group, $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 'updateCustomerGroup'
     *
     * @param  string $customer_group_id The customer group id (required)
     * @param  \Vend202601\Model\CustomerGroup $customer_group (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateCustomerGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updateCustomerGroupRequest($customer_group_id, $customer_group, string $contentType = self::contentTypes['updateCustomerGroup'][0])
    {

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

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


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



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


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

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