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

/**
 * Fortnox API
 *
 * # Documentation   The Fortnox API is organized around REST. This means that we’ve designed it to have resource-oriented URLs and be as predictable as possible for you as developer.  It also means that we use HTTP status codes when something goes wrong and HTTP verbs understod by many API clients around the web.  We use a modified version of OAuth2 for authentication to offer a secure way for both you and our users to interact.  The API is generally built to support both XML and JSON but in this documentation all the examples will be in JSON.  We encourage you to read all the articles in the [Guides & Good to Know section](https://www.fortnox.se/developer/guides-and-good-to-know/)</a> first, before going forward and learning about the different resources.  This to ensure you get an understanding of some of the shared components of the API such as parameters and error handling.  ## Rate limits  The limit per access-token is 25 requests per 5 seconds. This equals to 300 requests per minute.  [Read more about this here.](https://www.fortnox.se/developer/guides-and-good-to-know/rate-limits-for-fortnox-api/)  ## Query parameters  Use query parameters with the ?-character and separate parameters with the &-character.   **Example:**  GET - https://api.fortnox.se/3/invoices?accountnumberfrom=3000&accountnumberto=4000 Read more about our parameters [here](https://www.fortnox.se/developer/guides-and-good-to-know/parameters/)   Search the documentation using the search field in the top left corner.
 *
 * The version of the OpenAPI document: 
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.19.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 Fortnox\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 Fortnox\ApiException;
use Fortnox\Configuration;
use Fortnox\FormDataProcessor;
use Fortnox\HeaderSelector;
use Fortnox\ObjectSerializer;

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'batchUpdateResponseState' => [
            'application/json',
        ],
        'create11' => [
            'application/json',
        ],
        'get17' => [
            'application/json',
        ],
        'getAll9' => [
            'application/json',
        ],
        'getAttachedNotes' => [
            'application/json',
        ],
        'getCsvReport' => [
            'application/json',
        ],
        'getMatchedDocuments1' => [
            'application/json',
        ],
        'sendPurchaseOrder' => [
            'application/json',
        ],
        'sendPurchaseOrders' => [
            'application/json',
        ],
        'setDropshipManuallyCompleted' => [
            'application/json',
        ],
        'setManuallyCompleted' => [
            'application/json',
        ],
        'update6' => [
            'application/json',
        ],
        'updatePartial' => [
            'application/json',
        ],
        'updateResponseState' => [
            'application/json',
        ],
        'voidDocument5' => [
            '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 batchUpdateResponseState
     *
     * Update response states
     *
     * @param  int[]|null $ids List of purchase order ids. (optional)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['batchUpdateResponseState'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException
     */
    public function batchUpdateResponseState($ids = null, $response_state_change = null, string $contentType = self::contentTypes['batchUpdateResponseState'][0])
    {
        list($response) = $this->batchUpdateResponseStateWithHttpInfo($ids, $response_state_change, $contentType);
        return $response;
    }

    /**
     * Operation batchUpdateResponseStateWithHttpInfo
     *
     * Update response states
     *
     * @param  int[]|null $ids List of purchase order ids. (optional)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['batchUpdateResponseState'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function batchUpdateResponseStateWithHttpInfo($ids = null, $response_state_change = null, string $contentType = self::contentTypes['batchUpdateResponseState'][0])
    {
        $request = $this->batchUpdateResponseStateRequest($ids, $response_state_change, $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(
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehousePurchaseOrder',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation batchUpdateResponseStateAsync
     *
     * Update response states
     *
     * @param  int[]|null $ids List of purchase order ids. (optional)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['batchUpdateResponseState'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function batchUpdateResponseStateAsync($ids = null, $response_state_change = null, string $contentType = self::contentTypes['batchUpdateResponseState'][0])
    {
        return $this->batchUpdateResponseStateAsyncWithHttpInfo($ids, $response_state_change, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation batchUpdateResponseStateAsyncWithHttpInfo
     *
     * Update response states
     *
     * @param  int[]|null $ids List of purchase order ids. (optional)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['batchUpdateResponseState'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function batchUpdateResponseStateAsyncWithHttpInfo($ids = null, $response_state_change = null, string $contentType = self::contentTypes['batchUpdateResponseState'][0])
    {
        $returnType = '\Fortnox\Model\WarehousePurchaseOrder';
        $request = $this->batchUpdateResponseStateRequest($ids, $response_state_change, $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 'batchUpdateResponseState'
     *
     * @param  int[]|null $ids List of purchase order ids. (optional)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['batchUpdateResponseState'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function batchUpdateResponseStateRequest($ids = null, $response_state_change = null, string $contentType = self::contentTypes['batchUpdateResponseState'][0])
    {




        $resourcePath = '/api/warehouse/purchaseorders-v1/response';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

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




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

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


        $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
        );
    }

    /**
     * Operation create11
     *
     * Create Purchase Order
     *
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create11'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException
     */
    public function create11($purchase_order = null, string $contentType = self::contentTypes['create11'][0])
    {
        list($response) = $this->create11WithHttpInfo($purchase_order, $contentType);
        return $response;
    }

    /**
     * Operation create11WithHttpInfo
     *
     * Create Purchase Order
     *
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create11'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function create11WithHttpInfo($purchase_order = null, string $contentType = self::contentTypes['create11'][0])
    {
        $request = $this->create11Request($purchase_order, $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(
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehousePurchaseOrder',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation create11Async
     *
     * Create Purchase Order
     *
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create11'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function create11Async($purchase_order = null, string $contentType = self::contentTypes['create11'][0])
    {
        return $this->create11AsyncWithHttpInfo($purchase_order, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation create11AsyncWithHttpInfo
     *
     * Create Purchase Order
     *
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create11'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function create11AsyncWithHttpInfo($purchase_order = null, string $contentType = self::contentTypes['create11'][0])
    {
        $returnType = '\Fortnox\Model\WarehousePurchaseOrder';
        $request = $this->create11Request($purchase_order, $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 'create11'
     *
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create11'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function create11Request($purchase_order = null, string $contentType = self::contentTypes['create11'][0])
    {



        $resourcePath = '/api/warehouse/purchaseorders-v1';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;





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

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


        $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 get17
     *
     * Get Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  int|null $ignore_incoming_goods_id used for calculating the remaining ordered quantity. null will take the received quantity from all incoming goods (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get17'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException
     */
    public function get17($id, $ignore_incoming_goods_id = null, string $contentType = self::contentTypes['get17'][0])
    {
        list($response) = $this->get17WithHttpInfo($id, $ignore_incoming_goods_id, $contentType);
        return $response;
    }

    /**
     * Operation get17WithHttpInfo
     *
     * Get Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  int|null $ignore_incoming_goods_id used for calculating the remaining ordered quantity. null will take the received quantity from all incoming goods (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get17'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function get17WithHttpInfo($id, $ignore_incoming_goods_id = null, string $contentType = self::contentTypes['get17'][0])
    {
        $request = $this->get17Request($id, $ignore_incoming_goods_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(
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehousePurchaseOrder',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation get17Async
     *
     * Get Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  int|null $ignore_incoming_goods_id used for calculating the remaining ordered quantity. null will take the received quantity from all incoming goods (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get17'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function get17Async($id, $ignore_incoming_goods_id = null, string $contentType = self::contentTypes['get17'][0])
    {
        return $this->get17AsyncWithHttpInfo($id, $ignore_incoming_goods_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation get17AsyncWithHttpInfo
     *
     * Get Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  int|null $ignore_incoming_goods_id used for calculating the remaining ordered quantity. null will take the received quantity from all incoming goods (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get17'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function get17AsyncWithHttpInfo($id, $ignore_incoming_goods_id = null, string $contentType = self::contentTypes['get17'][0])
    {
        $returnType = '\Fortnox\Model\WarehousePurchaseOrder';
        $request = $this->get17Request($id, $ignore_incoming_goods_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 'get17'
     *
     * @param  int $id Purchase order id. (required)
     * @param  int|null $ignore_incoming_goods_id used for calculating the remaining ordered quantity. null will take the received quantity from all incoming goods (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get17'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function get17Request($id, $ignore_incoming_goods_id = null, string $contentType = self::contentTypes['get17'][0])
    {

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



        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

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


        // path params
        if ($id !== null) {
            $resourcePath = str_replace(
                '{' . 'id' . '}',
                ObjectSerializer::toPathValue($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);
            }
        }


        $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 getAll9
     *
     * List Purchase Orders
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll9'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException
     */
    public function getAll9($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, string $contentType = self::contentTypes['getAll9'][0])
    {
        list($response) = $this->getAll9WithHttpInfo($q, $supplier_number, $state, $item_id, $purchase_type, $internal_reference, $note, $contentType);
        return $response;
    }

    /**
     * Operation getAll9WithHttpInfo
     *
     * List Purchase Orders
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll9'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function getAll9WithHttpInfo($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, string $contentType = self::contentTypes['getAll9'][0])
    {
        $request = $this->getAll9Request($q, $supplier_number, $state, $item_id, $purchase_type, $internal_reference, $note, $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(
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehousePurchaseOrder',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getAll9Async
     *
     * List Purchase Orders
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll9'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAll9Async($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, string $contentType = self::contentTypes['getAll9'][0])
    {
        return $this->getAll9AsyncWithHttpInfo($q, $supplier_number, $state, $item_id, $purchase_type, $internal_reference, $note, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getAll9AsyncWithHttpInfo
     *
     * List Purchase Orders
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll9'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAll9AsyncWithHttpInfo($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, string $contentType = self::contentTypes['getAll9'][0])
    {
        $returnType = '\Fortnox\Model\WarehousePurchaseOrder';
        $request = $this->getAll9Request($q, $supplier_number, $state, $item_id, $purchase_type, $internal_reference, $note, $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 'getAll9'
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll9'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getAll9Request($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, string $contentType = self::contentTypes['getAll9'][0])
    {









        $resourcePath = '/api/warehouse/purchaseorders-v1';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $q,
            'q', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $supplier_number,
            'supplierNumber', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $state,
            'state', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_id,
            'itemId', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $purchase_type,
            'purchaseType', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $internal_reference,
            'internalReference', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $note,
            'note', // param base name
            'string', // 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);
            }
        }


        $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 getAttachedNotes
     *
     * Get notes
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAttachedNotes'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehousePurchaseOrderRowNote|\Fortnox\Model\WarehouseWebException
     */
    public function getAttachedNotes($id, string $contentType = self::contentTypes['getAttachedNotes'][0])
    {
        list($response) = $this->getAttachedNotesWithHttpInfo($id, $contentType);
        return $response;
    }

    /**
     * Operation getAttachedNotesWithHttpInfo
     *
     * Get notes
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAttachedNotes'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehousePurchaseOrderRowNote|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function getAttachedNotesWithHttpInfo($id, string $contentType = self::contentTypes['getAttachedNotes'][0])
    {
        $request = $this->getAttachedNotesRequest($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(
                        '\Fortnox\Model\WarehousePurchaseOrderRowNote',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehousePurchaseOrderRowNote',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehousePurchaseOrderRowNote',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getAttachedNotesAsync
     *
     * Get notes
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAttachedNotes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAttachedNotesAsync($id, string $contentType = self::contentTypes['getAttachedNotes'][0])
    {
        return $this->getAttachedNotesAsyncWithHttpInfo($id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getAttachedNotesAsyncWithHttpInfo
     *
     * Get notes
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAttachedNotes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAttachedNotesAsyncWithHttpInfo($id, string $contentType = self::contentTypes['getAttachedNotes'][0])
    {
        $returnType = '\Fortnox\Model\WarehousePurchaseOrderRowNote';
        $request = $this->getAttachedNotesRequest($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 'getAttachedNotes'
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAttachedNotes'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getAttachedNotesRequest($id, string $contentType = self::contentTypes['getAttachedNotes'][0])
    {

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


        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}/notes';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($id !== null) {
            $resourcePath = str_replace(
                '{' . 'id' . '}',
                ObjectSerializer::toPathValue($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);
            }
        }


        $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 getCsvReport
     *
     * Get CSV list of Purchase Orders
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  bool|null $show_purchase_type_column True to include the purchase type column, default is false. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCsvReport'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return string|\Fortnox\Model\WarehouseWebException
     */
    public function getCsvReport($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, $show_purchase_type_column = null, string $contentType = self::contentTypes['getCsvReport'][0])
    {
        list($response) = $this->getCsvReportWithHttpInfo($q, $supplier_number, $state, $item_id, $purchase_type, $internal_reference, $note, $show_purchase_type_column, $contentType);
        return $response;
    }

    /**
     * Operation getCsvReportWithHttpInfo
     *
     * Get CSV list of Purchase Orders
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  bool|null $show_purchase_type_column True to include the purchase type column, default is false. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCsvReport'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of string|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCsvReportWithHttpInfo($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, $show_purchase_type_column = null, string $contentType = self::contentTypes['getCsvReport'][0])
    {
        $request = $this->getCsvReportRequest($q, $supplier_number, $state, $item_id, $purchase_type, $internal_reference, $note, $show_purchase_type_column, $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(
                        'string',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'string',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getCsvReportAsync
     *
     * Get CSV list of Purchase Orders
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  bool|null $show_purchase_type_column True to include the purchase type column, default is false. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCsvReport'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCsvReportAsync($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, $show_purchase_type_column = null, string $contentType = self::contentTypes['getCsvReport'][0])
    {
        return $this->getCsvReportAsyncWithHttpInfo($q, $supplier_number, $state, $item_id, $purchase_type, $internal_reference, $note, $show_purchase_type_column, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCsvReportAsyncWithHttpInfo
     *
     * Get CSV list of Purchase Orders
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  bool|null $show_purchase_type_column True to include the purchase type column, default is false. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCsvReport'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCsvReportAsyncWithHttpInfo($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, $show_purchase_type_column = null, string $contentType = self::contentTypes['getCsvReport'][0])
    {
        $returnType = 'string';
        $request = $this->getCsvReportRequest($q, $supplier_number, $state, $item_id, $purchase_type, $internal_reference, $note, $show_purchase_type_column, $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 'getCsvReport'
     *
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;internalReference&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $state Include only documents with the given &#x60;purchaseOrderState&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $purchase_type Include only documents with the given &#x60;purchaseType&#x60; (optional)
     * @param  string|null $internal_reference Include only documents where &#x60;internalReference&#39; contains the given text (case-insensitive). (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  bool|null $show_purchase_type_column True to include the purchase type column, default is false. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCsvReport'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCsvReportRequest($q = null, $supplier_number = null, $state = null, $item_id = null, $purchase_type = null, $internal_reference = null, $note = null, $show_purchase_type_column = null, string $contentType = self::contentTypes['getCsvReport'][0])
    {










        $resourcePath = '/api/warehouse/purchaseorders-v1/csv';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $q,
            'q', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $supplier_number,
            'supplierNumber', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $state,
            'state', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_id,
            'itemId', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $purchase_type,
            'purchaseType', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $internal_reference,
            'internalReference', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $note,
            'note', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $show_purchase_type_column,
            'showPurchaseTypeColumn', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);




        $headers = $this->headerSelector->selectHeaders(
            ['text/csv', ],
            $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);
            }
        }


        $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 getMatchedDocuments1
     *
     * List matched documents
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getMatchedDocuments1'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehouseDocumentReference|\Fortnox\Model\WarehouseWebException
     */
    public function getMatchedDocuments1($id, string $contentType = self::contentTypes['getMatchedDocuments1'][0])
    {
        list($response) = $this->getMatchedDocuments1WithHttpInfo($id, $contentType);
        return $response;
    }

    /**
     * Operation getMatchedDocuments1WithHttpInfo
     *
     * List matched documents
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getMatchedDocuments1'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehouseDocumentReference|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function getMatchedDocuments1WithHttpInfo($id, string $contentType = self::contentTypes['getMatchedDocuments1'][0])
    {
        $request = $this->getMatchedDocuments1Request($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(
                        '\Fortnox\Model\WarehouseDocumentReference',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehouseDocumentReference',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseDocumentReference',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getMatchedDocuments1Async
     *
     * List matched documents
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getMatchedDocuments1'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getMatchedDocuments1Async($id, string $contentType = self::contentTypes['getMatchedDocuments1'][0])
    {
        return $this->getMatchedDocuments1AsyncWithHttpInfo($id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getMatchedDocuments1AsyncWithHttpInfo
     *
     * List matched documents
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getMatchedDocuments1'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getMatchedDocuments1AsyncWithHttpInfo($id, string $contentType = self::contentTypes['getMatchedDocuments1'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseDocumentReference';
        $request = $this->getMatchedDocuments1Request($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 'getMatchedDocuments1'
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getMatchedDocuments1'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getMatchedDocuments1Request($id, string $contentType = self::contentTypes['getMatchedDocuments1'][0])
    {

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


        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}/matches';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($id !== null) {
            $resourcePath = str_replace(
                '{' . 'id' . '}',
                ObjectSerializer::toPathValue($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);
            }
        }


        $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 sendPurchaseOrder
     *
     * Send purchase order via email
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrderMailSettings|null $settings see &lt;code&gt;PurchaseOrderMailSettings&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrder'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return void
     */
    public function sendPurchaseOrder($id, $settings = null, string $contentType = self::contentTypes['sendPurchaseOrder'][0])
    {
        $this->sendPurchaseOrderWithHttpInfo($id, $settings, $contentType);
    }

    /**
     * Operation sendPurchaseOrderWithHttpInfo
     *
     * Send purchase order via email
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrderMailSettings|null $settings see &lt;code&gt;PurchaseOrderMailSettings&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrder'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function sendPurchaseOrderWithHttpInfo($id, $settings = null, string $contentType = self::contentTypes['sendPurchaseOrder'][0])
    {
        $request = $this->sendPurchaseOrderRequest($id, $settings, $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();


            return [null, $statusCode, $response->getHeaders()];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation sendPurchaseOrderAsync
     *
     * Send purchase order via email
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrderMailSettings|null $settings see &lt;code&gt;PurchaseOrderMailSettings&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrder'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sendPurchaseOrderAsync($id, $settings = null, string $contentType = self::contentTypes['sendPurchaseOrder'][0])
    {
        return $this->sendPurchaseOrderAsyncWithHttpInfo($id, $settings, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation sendPurchaseOrderAsyncWithHttpInfo
     *
     * Send purchase order via email
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrderMailSettings|null $settings see &lt;code&gt;PurchaseOrderMailSettings&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrder'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sendPurchaseOrderAsyncWithHttpInfo($id, $settings = null, string $contentType = self::contentTypes['sendPurchaseOrder'][0])
    {
        $returnType = '';
        $request = $this->sendPurchaseOrderRequest($id, $settings, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $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 'sendPurchaseOrder'
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrderMailSettings|null $settings see &lt;code&gt;PurchaseOrderMailSettings&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrder'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function sendPurchaseOrderRequest($id, $settings = null, string $contentType = self::contentTypes['sendPurchaseOrder'][0])
    {

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



        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}/send';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

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


        $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 sendPurchaseOrders
     *
     * Sends multiple purchase orders via email
     *
     * @param  int[]|null $purchase_order_ids List of Purchase order ids. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrders'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return void
     */
    public function sendPurchaseOrders($purchase_order_ids = null, string $contentType = self::contentTypes['sendPurchaseOrders'][0])
    {
        $this->sendPurchaseOrdersWithHttpInfo($purchase_order_ids, $contentType);
    }

    /**
     * Operation sendPurchaseOrdersWithHttpInfo
     *
     * Sends multiple purchase orders via email
     *
     * @param  int[]|null $purchase_order_ids List of Purchase order ids. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrders'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function sendPurchaseOrdersWithHttpInfo($purchase_order_ids = null, string $contentType = self::contentTypes['sendPurchaseOrders'][0])
    {
        $request = $this->sendPurchaseOrdersRequest($purchase_order_ids, $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();


            return [null, $statusCode, $response->getHeaders()];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation sendPurchaseOrdersAsync
     *
     * Sends multiple purchase orders via email
     *
     * @param  int[]|null $purchase_order_ids List of Purchase order ids. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrders'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sendPurchaseOrdersAsync($purchase_order_ids = null, string $contentType = self::contentTypes['sendPurchaseOrders'][0])
    {
        return $this->sendPurchaseOrdersAsyncWithHttpInfo($purchase_order_ids, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation sendPurchaseOrdersAsyncWithHttpInfo
     *
     * Sends multiple purchase orders via email
     *
     * @param  int[]|null $purchase_order_ids List of Purchase order ids. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrders'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sendPurchaseOrdersAsyncWithHttpInfo($purchase_order_ids = null, string $contentType = self::contentTypes['sendPurchaseOrders'][0])
    {
        $returnType = '';
        $request = $this->sendPurchaseOrdersRequest($purchase_order_ids, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $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 'sendPurchaseOrders'
     *
     * @param  int[]|null $purchase_order_ids List of Purchase order ids. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['sendPurchaseOrders'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function sendPurchaseOrdersRequest($purchase_order_ids = null, string $contentType = self::contentTypes['sendPurchaseOrders'][0])
    {



        $resourcePath = '/api/warehouse/purchaseorders-v1/sendpurchaseorders';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;





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

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


        $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 setDropshipManuallyCompleted
     *
     * Manually complete dropship order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setDropshipManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehouseReleaseParentOrder|\Fortnox\Model\WarehouseWebException
     */
    public function setDropshipManuallyCompleted($id, string $contentType = self::contentTypes['setDropshipManuallyCompleted'][0])
    {
        list($response) = $this->setDropshipManuallyCompletedWithHttpInfo($id, $contentType);
        return $response;
    }

    /**
     * Operation setDropshipManuallyCompletedWithHttpInfo
     *
     * Manually complete dropship order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setDropshipManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehouseReleaseParentOrder|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function setDropshipManuallyCompletedWithHttpInfo($id, string $contentType = self::contentTypes['setDropshipManuallyCompleted'][0])
    {
        $request = $this->setDropshipManuallyCompletedRequest($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(
                        '\Fortnox\Model\WarehouseReleaseParentOrder',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehouseReleaseParentOrder',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseReleaseParentOrder',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation setDropshipManuallyCompletedAsync
     *
     * Manually complete dropship order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setDropshipManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function setDropshipManuallyCompletedAsync($id, string $contentType = self::contentTypes['setDropshipManuallyCompleted'][0])
    {
        return $this->setDropshipManuallyCompletedAsyncWithHttpInfo($id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation setDropshipManuallyCompletedAsyncWithHttpInfo
     *
     * Manually complete dropship order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setDropshipManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function setDropshipManuallyCompletedAsyncWithHttpInfo($id, string $contentType = self::contentTypes['setDropshipManuallyCompleted'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseReleaseParentOrder';
        $request = $this->setDropshipManuallyCompletedRequest($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 'setDropshipManuallyCompleted'
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setDropshipManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function setDropshipManuallyCompletedRequest($id, string $contentType = self::contentTypes['setDropshipManuallyCompleted'][0])
    {

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


        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}/dropshipcomplete';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($id !== null) {
            $resourcePath = str_replace(
                '{' . 'id' . '}',
                ObjectSerializer::toPathValue($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);
            }
        }


        $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
        );
    }

    /**
     * Operation setManuallyCompleted
     *
     * Manually complete Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return void
     */
    public function setManuallyCompleted($id, string $contentType = self::contentTypes['setManuallyCompleted'][0])
    {
        $this->setManuallyCompletedWithHttpInfo($id, $contentType);
    }

    /**
     * Operation setManuallyCompletedWithHttpInfo
     *
     * Manually complete Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function setManuallyCompletedWithHttpInfo($id, string $contentType = self::contentTypes['setManuallyCompleted'][0])
    {
        $request = $this->setManuallyCompletedRequest($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();


            return [null, $statusCode, $response->getHeaders()];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation setManuallyCompletedAsync
     *
     * Manually complete Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function setManuallyCompletedAsync($id, string $contentType = self::contentTypes['setManuallyCompleted'][0])
    {
        return $this->setManuallyCompletedAsyncWithHttpInfo($id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation setManuallyCompletedAsyncWithHttpInfo
     *
     * Manually complete Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function setManuallyCompletedAsyncWithHttpInfo($id, string $contentType = self::contentTypes['setManuallyCompleted'][0])
    {
        $returnType = '';
        $request = $this->setManuallyCompletedRequest($id, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $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 'setManuallyCompleted'
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['setManuallyCompleted'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function setManuallyCompletedRequest($id, string $contentType = self::contentTypes['setManuallyCompleted'][0])
    {

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


        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}/complete';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($id !== null) {
            $resourcePath = str_replace(
                '{' . 'id' . '}',
                ObjectSerializer::toPathValue($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);
            }
        }


        $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
        );
    }

    /**
     * Operation update6
     *
     * Update Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order The &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update6'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException
     */
    public function update6($id, $purchase_order = null, string $contentType = self::contentTypes['update6'][0])
    {
        list($response) = $this->update6WithHttpInfo($id, $purchase_order, $contentType);
        return $response;
    }

    /**
     * Operation update6WithHttpInfo
     *
     * Update Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order The &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update6'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function update6WithHttpInfo($id, $purchase_order = null, string $contentType = self::contentTypes['update6'][0])
    {
        $request = $this->update6Request($id, $purchase_order, $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(
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehousePurchaseOrder',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation update6Async
     *
     * Update Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order The &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update6'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function update6Async($id, $purchase_order = null, string $contentType = self::contentTypes['update6'][0])
    {
        return $this->update6AsyncWithHttpInfo($id, $purchase_order, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation update6AsyncWithHttpInfo
     *
     * Update Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order The &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update6'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function update6AsyncWithHttpInfo($id, $purchase_order = null, string $contentType = self::contentTypes['update6'][0])
    {
        $returnType = '\Fortnox\Model\WarehousePurchaseOrder';
        $request = $this->update6Request($id, $purchase_order, $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 'update6'
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePurchaseOrder|null $purchase_order The &lt;code&gt;PurchaseOrder&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update6'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function update6Request($id, $purchase_order = null, string $contentType = self::contentTypes['update6'][0])
    {

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



        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

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


        $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
        );
    }

    /**
     * Operation updatePartial
     *
     * Partial update Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePartialPurchaseOrder|null $changes the changes for the purchase order, see &lt;code&gt;PartialPurchaseOrder&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePartial'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehousePartialPurchaseOrder|\Fortnox\Model\WarehouseWebException
     */
    public function updatePartial($id, $changes = null, string $contentType = self::contentTypes['updatePartial'][0])
    {
        list($response) = $this->updatePartialWithHttpInfo($id, $changes, $contentType);
        return $response;
    }

    /**
     * Operation updatePartialWithHttpInfo
     *
     * Partial update Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePartialPurchaseOrder|null $changes the changes for the purchase order, see &lt;code&gt;PartialPurchaseOrder&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePartial'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehousePartialPurchaseOrder|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function updatePartialWithHttpInfo($id, $changes = null, string $contentType = self::contentTypes['updatePartial'][0])
    {
        $request = $this->updatePartialRequest($id, $changes, $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(
                        '\Fortnox\Model\WarehousePartialPurchaseOrder',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehousePartialPurchaseOrder',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehousePartialPurchaseOrder',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation updatePartialAsync
     *
     * Partial update Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePartialPurchaseOrder|null $changes the changes for the purchase order, see &lt;code&gt;PartialPurchaseOrder&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePartial'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updatePartialAsync($id, $changes = null, string $contentType = self::contentTypes['updatePartial'][0])
    {
        return $this->updatePartialAsyncWithHttpInfo($id, $changes, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updatePartialAsyncWithHttpInfo
     *
     * Partial update Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePartialPurchaseOrder|null $changes the changes for the purchase order, see &lt;code&gt;PartialPurchaseOrder&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePartial'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updatePartialAsyncWithHttpInfo($id, $changes = null, string $contentType = self::contentTypes['updatePartial'][0])
    {
        $returnType = '\Fortnox\Model\WarehousePartialPurchaseOrder';
        $request = $this->updatePartialRequest($id, $changes, $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 'updatePartial'
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehousePartialPurchaseOrder|null $changes the changes for the purchase order, see &lt;code&gt;PartialPurchaseOrder&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updatePartial'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updatePartialRequest($id, $changes = null, string $contentType = self::contentTypes['updatePartial'][0])
    {

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



        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}/partial';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

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


        $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(
            'PATCH',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation updateResponseState
     *
     * Update response state
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateResponseState'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException
     */
    public function updateResponseState($id, $response_state_change = null, string $contentType = self::contentTypes['updateResponseState'][0])
    {
        list($response) = $this->updateResponseStateWithHttpInfo($id, $response_state_change, $contentType);
        return $response;
    }

    /**
     * Operation updateResponseStateWithHttpInfo
     *
     * Update response state
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateResponseState'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \Fortnox\Model\WarehousePurchaseOrder|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateResponseStateWithHttpInfo($id, $response_state_change = null, string $contentType = self::contentTypes['updateResponseState'][0])
    {
        $request = $this->updateResponseStateRequest($id, $response_state_change, $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(
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\WarehouseWebException',
                        $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(
                '\Fortnox\Model\WarehousePurchaseOrder',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehousePurchaseOrder',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation updateResponseStateAsync
     *
     * Update response state
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateResponseState'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateResponseStateAsync($id, $response_state_change = null, string $contentType = self::contentTypes['updateResponseState'][0])
    {
        return $this->updateResponseStateAsyncWithHttpInfo($id, $response_state_change, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateResponseStateAsyncWithHttpInfo
     *
     * Update response state
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateResponseState'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateResponseStateAsyncWithHttpInfo($id, $response_state_change = null, string $contentType = self::contentTypes['updateResponseState'][0])
    {
        $returnType = '\Fortnox\Model\WarehousePurchaseOrder';
        $request = $this->updateResponseStateRequest($id, $response_state_change, $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 'updateResponseState'
     *
     * @param  int $id Purchase order id. (required)
     * @param  \Fortnox\Model\WarehouseResponseStateChange|null $response_state_change The new response state. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateResponseState'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updateResponseStateRequest($id, $response_state_change = null, string $contentType = self::contentTypes['updateResponseState'][0])
    {

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



        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}/response';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

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


        $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
        );
    }

    /**
     * Operation voidDocument5
     *
     * Void Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument5'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return void
     */
    public function voidDocument5($id, string $contentType = self::contentTypes['voidDocument5'][0])
    {
        $this->voidDocument5WithHttpInfo($id, $contentType);
    }

    /**
     * Operation voidDocument5WithHttpInfo
     *
     * Void Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument5'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function voidDocument5WithHttpInfo($id, string $contentType = self::contentTypes['voidDocument5'][0])
    {
        $request = $this->voidDocument5Request($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();


            return [null, $statusCode, $response->getHeaders()];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseWebException',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation voidDocument5Async
     *
     * Void Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument5'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function voidDocument5Async($id, string $contentType = self::contentTypes['voidDocument5'][0])
    {
        return $this->voidDocument5AsyncWithHttpInfo($id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation voidDocument5AsyncWithHttpInfo
     *
     * Void Purchase Order
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument5'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function voidDocument5AsyncWithHttpInfo($id, string $contentType = self::contentTypes['voidDocument5'][0])
    {
        $returnType = '';
        $request = $this->voidDocument5Request($id, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $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 'voidDocument5'
     *
     * @param  int $id Purchase order id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument5'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function voidDocument5Request($id, string $contentType = self::contentTypes['voidDocument5'][0])
    {

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


        $resourcePath = '/api/warehouse/purchaseorders-v1/{id}/void';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($id !== null) {
            $resourcePath = str_replace(
                '{' . 'id' . '}',
                ObjectSerializer::toPathValue($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);
            }
        }


        $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;
    }
}
