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

/**
 * API 2026-07
 *
 * Lightspeed Retail (X-Series) API.
 *
 * The version of the OpenAPI document: 2026-07
 * Contact: x-series.api@lightspeedhq.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.23.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 Vend\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 Vend\ApiException;
use Vend\Configuration;
use Vend\FormDataProcessor;
use Vend\HeaderSelector;
use Vend\ObjectSerializer;

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'getFulfillmentHistory' => [
            'application/json',
        ],
        'getFulfillmentSummary' => [
            'application/json',
        ],
        'postFulfillLineItems' => [
            'application/json',
        ],
        'postFulfillSale' => [
            'application/json',
        ],
        'postPackLineItems' => [
            'application/json',
        ],
        'postPickLineItems' => [
            '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 getFulfillmentHistory
     *
     * Get Fulfillment History
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  int|null $limit Maximum number of history entries to return per page. When omitted or set to 0, all entries are returned. (optional)
     * @param  string|null $cursor Opaque pagination cursor returned from a previous request. Pass this value to retrieve the next page of results. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentHistory'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend\Model\FulfillmentHistoryResponse
     */
    public function getFulfillmentHistory($fulfillment_id, $limit = null, $cursor = null, string $contentType = self::contentTypes['getFulfillmentHistory'][0])
    {
        list($response) = $this->getFulfillmentHistoryWithHttpInfo($fulfillment_id, $limit, $cursor, $contentType);
        return $response;
    }

    /**
     * Operation getFulfillmentHistoryWithHttpInfo
     *
     * Get Fulfillment History
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  int|null $limit Maximum number of history entries to return per page. When omitted or set to 0, all entries are returned. (optional)
     * @param  string|null $cursor Opaque pagination cursor returned from a previous request. Pass this value to retrieve the next page of results. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentHistory'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend\Model\FulfillmentHistoryResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getFulfillmentHistoryWithHttpInfo($fulfillment_id, $limit = null, $cursor = null, string $contentType = self::contentTypes['getFulfillmentHistory'][0])
    {
        $request = $this->getFulfillmentHistoryRequest($fulfillment_id, $limit, $cursor, $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(
                        '\Vend\Model\FulfillmentHistoryResponse',
                        $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(
                '\Vend\Model\FulfillmentHistoryResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend\Model\FulfillmentHistoryResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getFulfillmentHistoryAsync
     *
     * Get Fulfillment History
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  int|null $limit Maximum number of history entries to return per page. When omitted or set to 0, all entries are returned. (optional)
     * @param  string|null $cursor Opaque pagination cursor returned from a previous request. Pass this value to retrieve the next page of results. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentHistory'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getFulfillmentHistoryAsync($fulfillment_id, $limit = null, $cursor = null, string $contentType = self::contentTypes['getFulfillmentHistory'][0])
    {
        return $this->getFulfillmentHistoryAsyncWithHttpInfo($fulfillment_id, $limit, $cursor, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getFulfillmentHistoryAsyncWithHttpInfo
     *
     * Get Fulfillment History
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  int|null $limit Maximum number of history entries to return per page. When omitted or set to 0, all entries are returned. (optional)
     * @param  string|null $cursor Opaque pagination cursor returned from a previous request. Pass this value to retrieve the next page of results. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentHistory'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getFulfillmentHistoryAsyncWithHttpInfo($fulfillment_id, $limit = null, $cursor = null, string $contentType = self::contentTypes['getFulfillmentHistory'][0])
    {
        $returnType = '\Vend\Model\FulfillmentHistoryResponse';
        $request = $this->getFulfillmentHistoryRequest($fulfillment_id, $limit, $cursor, $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 'getFulfillmentHistory'
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  int|null $limit Maximum number of history entries to return per page. When omitted or set to 0, all entries are returned. (optional)
     * @param  string|null $cursor Opaque pagination cursor returned from a previous request. Pass this value to retrieve the next page of results. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentHistory'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getFulfillmentHistoryRequest($fulfillment_id, $limit = null, $cursor = null, string $contentType = self::contentTypes['getFulfillmentHistory'][0])
    {

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

        if ($limit !== null && $limit > 1000) {
            throw new \InvalidArgumentException('invalid value for "$limit" when calling FulfillmentsApi.getFulfillmentHistory, must be smaller than or equal to 1000.');
        }
        if ($limit !== null && $limit < 0) {
            throw new \InvalidArgumentException('invalid value for "$limit" when calling FulfillmentsApi.getFulfillmentHistory, must be bigger than or equal to 0.');
        }
        


        $resourcePath = '/fulfillments/{fulfillment_id}/history';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

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


        // path params
        if ($fulfillment_id !== null) {
            $resourcePath = str_replace(
                '{fulfillment_id}',
                ObjectSerializer::toPathValue($fulfillment_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 (JWT) 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 getFulfillmentSummary
     *
     * Get Fulfillments Summary
     *
     * @param  string[]|null $outlet_id Filter by outlet IDs (can be specified multiple times) (optional)
     * @param  string[]|null $sale_id Filter by sale IDs (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_type Filter by fulfillment types (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_state Filter by fulfillment states (can be specified multiple times) (optional)
     * @param  int|null $page_number Page number for pagination (1-based) (optional, default to 1)
     * @param  int|null $page_size Number of items per page (optional, default to 10)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentSummary'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend\Model\FulfillmentSummaryResponse
     */
    public function getFulfillmentSummary($outlet_id = null, $sale_id = null, $fulfillment_type = null, $fulfillment_state = null, $page_number = 1, $page_size = 10, string $contentType = self::contentTypes['getFulfillmentSummary'][0])
    {
        list($response) = $this->getFulfillmentSummaryWithHttpInfo($outlet_id, $sale_id, $fulfillment_type, $fulfillment_state, $page_number, $page_size, $contentType);
        return $response;
    }

    /**
     * Operation getFulfillmentSummaryWithHttpInfo
     *
     * Get Fulfillments Summary
     *
     * @param  string[]|null $outlet_id Filter by outlet IDs (can be specified multiple times) (optional)
     * @param  string[]|null $sale_id Filter by sale IDs (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_type Filter by fulfillment types (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_state Filter by fulfillment states (can be specified multiple times) (optional)
     * @param  int|null $page_number Page number for pagination (1-based) (optional, default to 1)
     * @param  int|null $page_size Number of items per page (optional, default to 10)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentSummary'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend\Model\FulfillmentSummaryResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getFulfillmentSummaryWithHttpInfo($outlet_id = null, $sale_id = null, $fulfillment_type = null, $fulfillment_state = null, $page_number = 1, $page_size = 10, string $contentType = self::contentTypes['getFulfillmentSummary'][0])
    {
        $request = $this->getFulfillmentSummaryRequest($outlet_id, $sale_id, $fulfillment_type, $fulfillment_state, $page_number, $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(
                        '\Vend\Model\FulfillmentSummaryResponse',
                        $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(
                '\Vend\Model\FulfillmentSummaryResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Vend\Model\FulfillmentSummaryResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getFulfillmentSummaryAsync
     *
     * Get Fulfillments Summary
     *
     * @param  string[]|null $outlet_id Filter by outlet IDs (can be specified multiple times) (optional)
     * @param  string[]|null $sale_id Filter by sale IDs (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_type Filter by fulfillment types (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_state Filter by fulfillment states (can be specified multiple times) (optional)
     * @param  int|null $page_number Page number for pagination (1-based) (optional, default to 1)
     * @param  int|null $page_size Number of items per page (optional, default to 10)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentSummary'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getFulfillmentSummaryAsync($outlet_id = null, $sale_id = null, $fulfillment_type = null, $fulfillment_state = null, $page_number = 1, $page_size = 10, string $contentType = self::contentTypes['getFulfillmentSummary'][0])
    {
        return $this->getFulfillmentSummaryAsyncWithHttpInfo($outlet_id, $sale_id, $fulfillment_type, $fulfillment_state, $page_number, $page_size, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getFulfillmentSummaryAsyncWithHttpInfo
     *
     * Get Fulfillments Summary
     *
     * @param  string[]|null $outlet_id Filter by outlet IDs (can be specified multiple times) (optional)
     * @param  string[]|null $sale_id Filter by sale IDs (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_type Filter by fulfillment types (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_state Filter by fulfillment states (can be specified multiple times) (optional)
     * @param  int|null $page_number Page number for pagination (1-based) (optional, default to 1)
     * @param  int|null $page_size Number of items per page (optional, default to 10)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentSummary'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getFulfillmentSummaryAsyncWithHttpInfo($outlet_id = null, $sale_id = null, $fulfillment_type = null, $fulfillment_state = null, $page_number = 1, $page_size = 10, string $contentType = self::contentTypes['getFulfillmentSummary'][0])
    {
        $returnType = '\Vend\Model\FulfillmentSummaryResponse';
        $request = $this->getFulfillmentSummaryRequest($outlet_id, $sale_id, $fulfillment_type, $fulfillment_state, $page_number, $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 'getFulfillmentSummary'
     *
     * @param  string[]|null $outlet_id Filter by outlet IDs (can be specified multiple times) (optional)
     * @param  string[]|null $sale_id Filter by sale IDs (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_type Filter by fulfillment types (can be specified multiple times) (optional)
     * @param  string[]|null $fulfillment_state Filter by fulfillment states (can be specified multiple times) (optional)
     * @param  int|null $page_number Page number for pagination (1-based) (optional, default to 1)
     * @param  int|null $page_size Number of items per page (optional, default to 10)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getFulfillmentSummary'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getFulfillmentSummaryRequest($outlet_id = null, $sale_id = null, $fulfillment_type = null, $fulfillment_state = null, $page_number = 1, $page_size = 10, string $contentType = self::contentTypes['getFulfillmentSummary'][0])
    {





        if ($page_number !== null && $page_number < 1) {
            throw new \InvalidArgumentException('invalid value for "$page_number" when calling FulfillmentsApi.getFulfillmentSummary, must be bigger than or equal to 1.');
        }
        
        if ($page_size !== null && $page_size > 100) {
            throw new \InvalidArgumentException('invalid value for "$page_size" when calling FulfillmentsApi.getFulfillmentSummary, must be smaller than or equal to 100.');
        }
        if ($page_size !== null && $page_size < 1) {
            throw new \InvalidArgumentException('invalid value for "$page_size" when calling FulfillmentsApi.getFulfillmentSummary, must be bigger than or equal to 1.');
        }
        

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

        // 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(
            $sale_id,
            'sale_id', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fulfillment_type,
            'fulfillment_type', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fulfillment_state,
            'fulfillment_state', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page_number,
            'page_number', // 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 (JWT) 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 postFulfillLineItems
     *
     * Fulfill line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\FulfillLineItemsRequest $fulfill_line_items_request fulfill_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillLineItems'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend\Model\FulfillLineItemsResponse
     */
    public function postFulfillLineItems($fulfillment_id, $fulfill_line_items_request, string $contentType = self::contentTypes['postFulfillLineItems'][0])
    {
        list($response) = $this->postFulfillLineItemsWithHttpInfo($fulfillment_id, $fulfill_line_items_request, $contentType);
        return $response;
    }

    /**
     * Operation postFulfillLineItemsWithHttpInfo
     *
     * Fulfill line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\FulfillLineItemsRequest $fulfill_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillLineItems'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend\Model\FulfillLineItemsResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postFulfillLineItemsWithHttpInfo($fulfillment_id, $fulfill_line_items_request, string $contentType = self::contentTypes['postFulfillLineItems'][0])
    {
        $request = $this->postFulfillLineItemsRequest($fulfillment_id, $fulfill_line_items_request, $contentType);

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

            $statusCode = $response->getStatusCode();


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

            throw $e;
        }
    }

    /**
     * Operation postFulfillLineItemsAsync
     *
     * Fulfill line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\FulfillLineItemsRequest $fulfill_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillLineItems'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postFulfillLineItemsAsync($fulfillment_id, $fulfill_line_items_request, string $contentType = self::contentTypes['postFulfillLineItems'][0])
    {
        return $this->postFulfillLineItemsAsyncWithHttpInfo($fulfillment_id, $fulfill_line_items_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postFulfillLineItemsAsyncWithHttpInfo
     *
     * Fulfill line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\FulfillLineItemsRequest $fulfill_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillLineItems'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postFulfillLineItemsAsyncWithHttpInfo($fulfillment_id, $fulfill_line_items_request, string $contentType = self::contentTypes['postFulfillLineItems'][0])
    {
        $returnType = '\Vend\Model\FulfillLineItemsResponse';
        $request = $this->postFulfillLineItemsRequest($fulfillment_id, $fulfill_line_items_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 'postFulfillLineItems'
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\FulfillLineItemsRequest $fulfill_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillLineItems'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function postFulfillLineItemsRequest($fulfillment_id, $fulfill_line_items_request, string $contentType = self::contentTypes['postFulfillLineItems'][0])
    {

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

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


        $resourcePath = '/fulfillments/{fulfillment_id}/fulfill';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($fulfill_line_items_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($fulfill_line_items_request));
            } else {
                $httpBody = $fulfill_line_items_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 (JWT) 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 postFulfillSale
     *
     * Fulfill a Sale
     *
     * @param  \Vend\Model\FulfillSaleRequest|null $fulfill_sale_request fulfill_sale_request (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillSale'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend\Model\FulfillSaleResponse
     */
    public function postFulfillSale($fulfill_sale_request = null, string $contentType = self::contentTypes['postFulfillSale'][0])
    {
        list($response) = $this->postFulfillSaleWithHttpInfo($fulfill_sale_request, $contentType);
        return $response;
    }

    /**
     * Operation postFulfillSaleWithHttpInfo
     *
     * Fulfill a Sale
     *
     * @param  \Vend\Model\FulfillSaleRequest|null $fulfill_sale_request (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillSale'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend\Model\FulfillSaleResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postFulfillSaleWithHttpInfo($fulfill_sale_request = null, string $contentType = self::contentTypes['postFulfillSale'][0])
    {
        $request = $this->postFulfillSaleRequest($fulfill_sale_request, $contentType);

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

            $statusCode = $response->getStatusCode();


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

            throw $e;
        }
    }

    /**
     * Operation postFulfillSaleAsync
     *
     * Fulfill a Sale
     *
     * @param  \Vend\Model\FulfillSaleRequest|null $fulfill_sale_request (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillSale'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postFulfillSaleAsync($fulfill_sale_request = null, string $contentType = self::contentTypes['postFulfillSale'][0])
    {
        return $this->postFulfillSaleAsyncWithHttpInfo($fulfill_sale_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postFulfillSaleAsyncWithHttpInfo
     *
     * Fulfill a Sale
     *
     * @param  \Vend\Model\FulfillSaleRequest|null $fulfill_sale_request (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillSale'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postFulfillSaleAsyncWithHttpInfo($fulfill_sale_request = null, string $contentType = self::contentTypes['postFulfillSale'][0])
    {
        $returnType = '\Vend\Model\FulfillSaleResponse';
        $request = $this->postFulfillSaleRequest($fulfill_sale_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 'postFulfillSale'
     *
     * @param  \Vend\Model\FulfillSaleRequest|null $fulfill_sale_request (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postFulfillSale'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function postFulfillSaleRequest($fulfill_sale_request = null, string $contentType = self::contentTypes['postFulfillSale'][0])
    {



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





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

        // for model (json/xml)
        if (isset($fulfill_sale_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($fulfill_sale_request));
            } else {
                $httpBody = $fulfill_sale_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 (JWT) 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 postPackLineItems
     *
     * Partial Pack line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PackLineItemsRequest $pack_line_items_request pack_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPackLineItems'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend\Model\PackLineItemsResponse
     */
    public function postPackLineItems($fulfillment_id, $pack_line_items_request, string $contentType = self::contentTypes['postPackLineItems'][0])
    {
        list($response) = $this->postPackLineItemsWithHttpInfo($fulfillment_id, $pack_line_items_request, $contentType);
        return $response;
    }

    /**
     * Operation postPackLineItemsWithHttpInfo
     *
     * Partial Pack line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PackLineItemsRequest $pack_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPackLineItems'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend\Model\PackLineItemsResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postPackLineItemsWithHttpInfo($fulfillment_id, $pack_line_items_request, string $contentType = self::contentTypes['postPackLineItems'][0])
    {
        $request = $this->postPackLineItemsRequest($fulfillment_id, $pack_line_items_request, $contentType);

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

            $statusCode = $response->getStatusCode();


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

            throw $e;
        }
    }

    /**
     * Operation postPackLineItemsAsync
     *
     * Partial Pack line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PackLineItemsRequest $pack_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPackLineItems'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postPackLineItemsAsync($fulfillment_id, $pack_line_items_request, string $contentType = self::contentTypes['postPackLineItems'][0])
    {
        return $this->postPackLineItemsAsyncWithHttpInfo($fulfillment_id, $pack_line_items_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postPackLineItemsAsyncWithHttpInfo
     *
     * Partial Pack line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PackLineItemsRequest $pack_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPackLineItems'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postPackLineItemsAsyncWithHttpInfo($fulfillment_id, $pack_line_items_request, string $contentType = self::contentTypes['postPackLineItems'][0])
    {
        $returnType = '\Vend\Model\PackLineItemsResponse';
        $request = $this->postPackLineItemsRequest($fulfillment_id, $pack_line_items_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 'postPackLineItems'
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PackLineItemsRequest $pack_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPackLineItems'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function postPackLineItemsRequest($fulfillment_id, $pack_line_items_request, string $contentType = self::contentTypes['postPackLineItems'][0])
    {

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

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


        $resourcePath = '/fulfillments/{fulfillment_id}/pack';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($pack_line_items_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($pack_line_items_request));
            } else {
                $httpBody = $pack_line_items_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 (JWT) 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 postPickLineItems
     *
     * Partial Pick line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PickLineItemsRequest $pick_line_items_request pick_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPickLineItems'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Vend\Model\PickLineItemsResponse
     */
    public function postPickLineItems($fulfillment_id, $pick_line_items_request, string $contentType = self::contentTypes['postPickLineItems'][0])
    {
        list($response) = $this->postPickLineItemsWithHttpInfo($fulfillment_id, $pick_line_items_request, $contentType);
        return $response;
    }

    /**
     * Operation postPickLineItemsWithHttpInfo
     *
     * Partial Pick line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PickLineItemsRequest $pick_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPickLineItems'] to see the possible values for this operation
     *
     * @throws \Vend\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Vend\Model\PickLineItemsResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function postPickLineItemsWithHttpInfo($fulfillment_id, $pick_line_items_request, string $contentType = self::contentTypes['postPickLineItems'][0])
    {
        $request = $this->postPickLineItemsRequest($fulfillment_id, $pick_line_items_request, $contentType);

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

            $statusCode = $response->getStatusCode();


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

            throw $e;
        }
    }

    /**
     * Operation postPickLineItemsAsync
     *
     * Partial Pick line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PickLineItemsRequest $pick_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPickLineItems'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postPickLineItemsAsync($fulfillment_id, $pick_line_items_request, string $contentType = self::contentTypes['postPickLineItems'][0])
    {
        return $this->postPickLineItemsAsyncWithHttpInfo($fulfillment_id, $pick_line_items_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation postPickLineItemsAsyncWithHttpInfo
     *
     * Partial Pick line items within a sale
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PickLineItemsRequest $pick_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPickLineItems'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function postPickLineItemsAsyncWithHttpInfo($fulfillment_id, $pick_line_items_request, string $contentType = self::contentTypes['postPickLineItems'][0])
    {
        $returnType = '\Vend\Model\PickLineItemsResponse';
        $request = $this->postPickLineItemsRequest($fulfillment_id, $pick_line_items_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 'postPickLineItems'
     *
     * @param  string $fulfillment_id The unique identifier of the fulfillment (required)
     * @param  \Vend\Model\PickLineItemsRequest $pick_line_items_request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['postPickLineItems'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function postPickLineItemsRequest($fulfillment_id, $pick_line_items_request, string $contentType = self::contentTypes['postPickLineItems'][0])
    {

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

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


        $resourcePath = '/fulfillments/{fulfillment_id}/pick';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($pick_line_items_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($pick_line_items_request));
            } else {
                $httpBody = $pick_line_items_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 (JWT) authentication (access token)
        if (!empty($this->config->getAccessToken())) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

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

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

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

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

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

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

        return $options;
    }

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

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

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

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