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

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'completed' => [
            'application/json',
        ],
        'create9' => [
            'application/json',
        ],
        'get15' => [
            'application/json',
        ],
        'getAll7' => [
            'application/json',
        ],
        'patch' => [
            'application/json',
        ],
        'release6' => [
            'application/json',
        ],
        'save2' => [
            'application/json',
        ],
        'voidDocument4' => [
            '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 completed
     *
     * Complete Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string|null $booking_date Date for bookkeeping in format &#x60;\&quot;YYYY-MM-DD\&quot;&#x60;. Must be between document&#39;s release date (inclusive) and today&#39;s date (inclusive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['completed'] 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 completed($id, $booking_date = null, string $contentType = self::contentTypes['completed'][0])
    {
        $this->completedWithHttpInfo($id, $booking_date, $contentType);
    }

    /**
     * Operation completedWithHttpInfo
     *
     * Complete Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string|null $booking_date Date for bookkeeping in format &#x60;\&quot;YYYY-MM-DD\&quot;&#x60;. Must be between document&#39;s release date (inclusive) and today&#39;s date (inclusive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['completed'] 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 completedWithHttpInfo($id, $booking_date = null, string $contentType = self::contentTypes['completed'][0])
    {
        $request = $this->completedRequest($id, $booking_date, $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 completedAsync
     *
     * Complete Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string|null $booking_date Date for bookkeeping in format &#x60;\&quot;YYYY-MM-DD\&quot;&#x60;. Must be between document&#39;s release date (inclusive) and today&#39;s date (inclusive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['completed'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function completedAsync($id, $booking_date = null, string $contentType = self::contentTypes['completed'][0])
    {
        return $this->completedAsyncWithHttpInfo($id, $booking_date, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation completedAsyncWithHttpInfo
     *
     * Complete Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string|null $booking_date Date for bookkeeping in format &#x60;\&quot;YYYY-MM-DD\&quot;&#x60;. Must be between document&#39;s release date (inclusive) and today&#39;s date (inclusive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['completed'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function completedAsyncWithHttpInfo($id, $booking_date = null, string $contentType = self::contentTypes['completed'][0])
    {
        $returnType = '';
        $request = $this->completedRequest($id, $booking_date, $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 'completed'
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string|null $booking_date Date for bookkeeping in format &#x60;\&quot;YYYY-MM-DD\&quot;&#x60;. Must be between document&#39;s release date (inclusive) and today&#39;s date (inclusive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['completed'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function completedRequest($id, $booking_date = null, string $contentType = self::contentTypes['completed'][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 completed'
            );
        }



        $resourcePath = '/api/warehouse/incominggoods-v1/{id}/completed';
        $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($booking_date)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($booking_date));
            } else {
                $httpBody = $booking_date;
            }
        } 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 create9
     *
     * Create Incoming Goods document
     *
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods The &lt;code&gt;IncomingGoods&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create9'] 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\WarehouseIncomingGoods|\Fortnox\Model\WarehouseWebException
     */
    public function create9($incoming_goods = null, string $contentType = self::contentTypes['create9'][0])
    {
        list($response) = $this->create9WithHttpInfo($incoming_goods, $contentType);
        return $response;
    }

    /**
     * Operation create9WithHttpInfo
     *
     * Create Incoming Goods document
     *
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods The &lt;code&gt;IncomingGoods&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create9'] 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\WarehouseIncomingGoods|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function create9WithHttpInfo($incoming_goods = null, string $contentType = self::contentTypes['create9'][0])
    {
        $request = $this->create9Request($incoming_goods, $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\WarehouseIncomingGoods',
                        $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\WarehouseIncomingGoods',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseIncomingGoods',
                        $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 create9Async
     *
     * Create Incoming Goods document
     *
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods The &lt;code&gt;IncomingGoods&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create9'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function create9Async($incoming_goods = null, string $contentType = self::contentTypes['create9'][0])
    {
        return $this->create9AsyncWithHttpInfo($incoming_goods, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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



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





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

        // for model (json/xml)
        if (isset($incoming_goods)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($incoming_goods));
            } else {
                $httpBody = $incoming_goods;
            }
        } 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 get15
     *
     * Get Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  int|null $ignore_supplier_invoice_id This Supplier Invoice id will be excluded when calculating the takenQuantity. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get15'] 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\WarehouseIncomingGoods|\Fortnox\Model\WarehouseWebException
     */
    public function get15($id, $ignore_supplier_invoice_id = null, string $contentType = self::contentTypes['get15'][0])
    {
        list($response) = $this->get15WithHttpInfo($id, $ignore_supplier_invoice_id, $contentType);
        return $response;
    }

    /**
     * Operation get15WithHttpInfo
     *
     * Get Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  int|null $ignore_supplier_invoice_id This Supplier Invoice id will be excluded when calculating the takenQuantity. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get15'] 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\WarehouseIncomingGoods|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function get15WithHttpInfo($id, $ignore_supplier_invoice_id = null, string $contentType = self::contentTypes['get15'][0])
    {
        $request = $this->get15Request($id, $ignore_supplier_invoice_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\WarehouseIncomingGoods',
                        $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\WarehouseIncomingGoods',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseIncomingGoods',
                        $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 get15Async
     *
     * Get Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  int|null $ignore_supplier_invoice_id This Supplier Invoice id will be excluded when calculating the takenQuantity. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get15'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function get15Async($id, $ignore_supplier_invoice_id = null, string $contentType = self::contentTypes['get15'][0])
    {
        return $this->get15AsyncWithHttpInfo($id, $ignore_supplier_invoice_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation get15AsyncWithHttpInfo
     *
     * Get Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  int|null $ignore_supplier_invoice_id This Supplier Invoice id will be excluded when calculating the takenQuantity. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get15'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function get15AsyncWithHttpInfo($id, $ignore_supplier_invoice_id = null, string $contentType = self::contentTypes['get15'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseIncomingGoods';
        $request = $this->get15Request($id, $ignore_supplier_invoice_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 'get15'
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  int|null $ignore_supplier_invoice_id This Supplier Invoice id will be excluded when calculating the takenQuantity. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get15'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function get15Request($id, $ignore_supplier_invoice_id = null, string $contentType = self::contentTypes['get15'][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 get15'
            );
        }



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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $ignore_supplier_invoice_id,
            'ignoreSupplierInvoiceId', // 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 getAll7
     *
     * List Incoming Goods Documents
     *
     * @param  bool|null $released &#x60;true&#x60; to include only released documents.  &#x60;false&#x60; to include only non-released documents. (optional)
     * @param  bool|null $completed &#x60;true&#x60; to include only completed documents.  &#x60;false&#x60; to include only non-completed documents. (optional)
     * @param  bool|null $voided &#x60;true&#x60; to include only voided documents.  &#x60;false&#x60; to include only non-voided documents. (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $delivery_note Include only documents where &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll7'] 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\WarehouseIncomingGoodsListRow[]|\Fortnox\Model\WarehouseWebException
     */
    public function getAll7($released = null, $completed = null, $voided = null, $supplier_number = null, $item_id = null, $note = null, $delivery_note = null, $q = null, string $contentType = self::contentTypes['getAll7'][0])
    {
        list($response) = $this->getAll7WithHttpInfo($released, $completed, $voided, $supplier_number, $item_id, $note, $delivery_note, $q, $contentType);
        return $response;
    }

    /**
     * Operation getAll7WithHttpInfo
     *
     * List Incoming Goods Documents
     *
     * @param  bool|null $released &#x60;true&#x60; to include only released documents.  &#x60;false&#x60; to include only non-released documents. (optional)
     * @param  bool|null $completed &#x60;true&#x60; to include only completed documents.  &#x60;false&#x60; to include only non-completed documents. (optional)
     * @param  bool|null $voided &#x60;true&#x60; to include only voided documents.  &#x60;false&#x60; to include only non-voided documents. (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $delivery_note Include only documents where &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll7'] 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\WarehouseIncomingGoodsListRow[]|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function getAll7WithHttpInfo($released = null, $completed = null, $voided = null, $supplier_number = null, $item_id = null, $note = null, $delivery_note = null, $q = null, string $contentType = self::contentTypes['getAll7'][0])
    {
        $request = $this->getAll7Request($released, $completed, $voided, $supplier_number, $item_id, $note, $delivery_note, $q, $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\WarehouseIncomingGoodsListRow[]',
                        $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\WarehouseIncomingGoodsListRow[]',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseIncomingGoodsListRow[]',
                        $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 getAll7Async
     *
     * List Incoming Goods Documents
     *
     * @param  bool|null $released &#x60;true&#x60; to include only released documents.  &#x60;false&#x60; to include only non-released documents. (optional)
     * @param  bool|null $completed &#x60;true&#x60; to include only completed documents.  &#x60;false&#x60; to include only non-completed documents. (optional)
     * @param  bool|null $voided &#x60;true&#x60; to include only voided documents.  &#x60;false&#x60; to include only non-voided documents. (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $delivery_note Include only documents where &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll7'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAll7Async($released = null, $completed = null, $voided = null, $supplier_number = null, $item_id = null, $note = null, $delivery_note = null, $q = null, string $contentType = self::contentTypes['getAll7'][0])
    {
        return $this->getAll7AsyncWithHttpInfo($released, $completed, $voided, $supplier_number, $item_id, $note, $delivery_note, $q, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getAll7AsyncWithHttpInfo
     *
     * List Incoming Goods Documents
     *
     * @param  bool|null $released &#x60;true&#x60; to include only released documents.  &#x60;false&#x60; to include only non-released documents. (optional)
     * @param  bool|null $completed &#x60;true&#x60; to include only completed documents.  &#x60;false&#x60; to include only non-completed documents. (optional)
     * @param  bool|null $voided &#x60;true&#x60; to include only voided documents.  &#x60;false&#x60; to include only non-voided documents. (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $delivery_note Include only documents where &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll7'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAll7AsyncWithHttpInfo($released = null, $completed = null, $voided = null, $supplier_number = null, $item_id = null, $note = null, $delivery_note = null, $q = null, string $contentType = self::contentTypes['getAll7'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseIncomingGoodsListRow[]';
        $request = $this->getAll7Request($released, $completed, $voided, $supplier_number, $item_id, $note, $delivery_note, $q, $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 'getAll7'
     *
     * @param  bool|null $released &#x60;true&#x60; to include only released documents.  &#x60;false&#x60; to include only non-released documents. (optional)
     * @param  bool|null $completed &#x60;true&#x60; to include only completed documents.  &#x60;false&#x60; to include only non-completed documents. (optional)
     * @param  bool|null $voided &#x60;true&#x60; to include only voided documents.  &#x60;false&#x60; to include only non-voided documents. (optional)
     * @param  string|null $supplier_number Include only documents with the given &#x60;supplierNumber&#x60;. (optional)
     * @param  string|null $item_id Include only documents with the given &#x60;itemId&#x60;. (optional)
     * @param  string|null $note Include only documents where &#x60;note&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $delivery_note Include only documents where &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string|null $q Include only documents where &#x60;id&#x60; or &#x60;deliveryNote&#x60;-field contains the given text (case-insensitive). (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll7'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getAll7Request($released = null, $completed = null, $voided = null, $supplier_number = null, $item_id = null, $note = null, $delivery_note = null, $q = null, string $contentType = self::contentTypes['getAll7'][0])
    {










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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $released,
            'released', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $completed,
            'completed', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $voided,
            'voided', // param base name
            'boolean', // 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(
            $item_id,
            'itemId', // 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(
            $delivery_note,
            'deliveryNote', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $q,
            'q', // 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 patch
     *
     * Partial update Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods the incoming goods document to update. The partial update updates                       &lt;code&gt;note&lt;/code&gt;, &lt;code&gt;deliveryNoteId&lt;/code&gt;, &lt;code&gt;supplierName&lt;/code&gt; and &lt;code&gt;hasDeliveryNote&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['patch'] 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\WarehouseIncomingGoods|\Fortnox\Model\WarehouseWebException
     */
    public function patch($id, $incoming_goods = null, string $contentType = self::contentTypes['patch'][0])
    {
        list($response) = $this->patchWithHttpInfo($id, $incoming_goods, $contentType);
        return $response;
    }

    /**
     * Operation patchWithHttpInfo
     *
     * Partial update Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods the incoming goods document to update. The partial update updates                       &lt;code&gt;note&lt;/code&gt;, &lt;code&gt;deliveryNoteId&lt;/code&gt;, &lt;code&gt;supplierName&lt;/code&gt; and &lt;code&gt;hasDeliveryNote&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['patch'] 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\WarehouseIncomingGoods|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function patchWithHttpInfo($id, $incoming_goods = null, string $contentType = self::contentTypes['patch'][0])
    {
        $request = $this->patchRequest($id, $incoming_goods, $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\WarehouseIncomingGoods',
                        $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\WarehouseIncomingGoods',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseIncomingGoods',
                        $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 patchAsync
     *
     * Partial update Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods the incoming goods document to update. The partial update updates                       &lt;code&gt;note&lt;/code&gt;, &lt;code&gt;deliveryNoteId&lt;/code&gt;, &lt;code&gt;supplierName&lt;/code&gt; and &lt;code&gt;hasDeliveryNote&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['patch'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function patchAsync($id, $incoming_goods = null, string $contentType = self::contentTypes['patch'][0])
    {
        return $this->patchAsyncWithHttpInfo($id, $incoming_goods, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation patchAsyncWithHttpInfo
     *
     * Partial update Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods the incoming goods document to update. The partial update updates                       &lt;code&gt;note&lt;/code&gt;, &lt;code&gt;deliveryNoteId&lt;/code&gt;, &lt;code&gt;supplierName&lt;/code&gt; and &lt;code&gt;hasDeliveryNote&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['patch'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function patchAsyncWithHttpInfo($id, $incoming_goods = null, string $contentType = self::contentTypes['patch'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseIncomingGoods';
        $request = $this->patchRequest($id, $incoming_goods, $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 'patch'
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods the incoming goods document to update. The partial update updates                       &lt;code&gt;note&lt;/code&gt;, &lt;code&gt;deliveryNoteId&lt;/code&gt;, &lt;code&gt;supplierName&lt;/code&gt; and &lt;code&gt;hasDeliveryNote&lt;/code&gt; (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['patch'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function patchRequest($id, $incoming_goods = null, string $contentType = self::contentTypes['patch'][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 patch'
            );
        }



        $resourcePath = '/api/warehouse/incominggoods-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($incoming_goods)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($incoming_goods));
            } else {
                $httpBody = $incoming_goods;
            }
        } 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 release6
     *
     * Release Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['release6'] 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 release6($id, string $contentType = self::contentTypes['release6'][0])
    {
        $this->release6WithHttpInfo($id, $contentType);
    }

    /**
     * Operation release6WithHttpInfo
     *
     * Release Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['release6'] 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 release6WithHttpInfo($id, string $contentType = self::contentTypes['release6'][0])
    {
        $request = $this->release6Request($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 release6Async
     *
     * Release Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['release6'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function release6Async($id, string $contentType = self::contentTypes['release6'][0])
    {
        return $this->release6AsyncWithHttpInfo($id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation release6AsyncWithHttpInfo
     *
     * Release Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['release6'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function release6AsyncWithHttpInfo($id, string $contentType = self::contentTypes['release6'][0])
    {
        $returnType = '';
        $request = $this->release6Request($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 'release6'
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['release6'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function release6Request($id, string $contentType = self::contentTypes['release6'][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 release6'
            );
        }


        $resourcePath = '/api/warehouse/incominggoods-v1/{id}/release';
        $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 save2
     *
     * Update Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods The &lt;code&gt;IncomingGoods&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['save2'] 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\WarehouseIncomingGoods|\Fortnox\Model\WarehouseWebException
     */
    public function save2($id, $incoming_goods = null, string $contentType = self::contentTypes['save2'][0])
    {
        list($response) = $this->save2WithHttpInfo($id, $incoming_goods, $contentType);
        return $response;
    }

    /**
     * Operation save2WithHttpInfo
     *
     * Update Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods The &lt;code&gt;IncomingGoods&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['save2'] 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\WarehouseIncomingGoods|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function save2WithHttpInfo($id, $incoming_goods = null, string $contentType = self::contentTypes['save2'][0])
    {
        $request = $this->save2Request($id, $incoming_goods, $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\WarehouseIncomingGoods',
                        $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\WarehouseIncomingGoods',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseIncomingGoods',
                        $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 save2Async
     *
     * Update Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods The &lt;code&gt;IncomingGoods&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['save2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function save2Async($id, $incoming_goods = null, string $contentType = self::contentTypes['save2'][0])
    {
        return $this->save2AsyncWithHttpInfo($id, $incoming_goods, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation save2AsyncWithHttpInfo
     *
     * Update Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods The &lt;code&gt;IncomingGoods&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['save2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function save2AsyncWithHttpInfo($id, $incoming_goods = null, string $contentType = self::contentTypes['save2'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseIncomingGoods';
        $request = $this->save2Request($id, $incoming_goods, $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 'save2'
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  \Fortnox\Model\WarehouseIncomingGoods|null $incoming_goods The &lt;code&gt;IncomingGoods&lt;/code&gt; document. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['save2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function save2Request($id, $incoming_goods = null, string $contentType = self::contentTypes['save2'][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 save2'
            );
        }



        $resourcePath = '/api/warehouse/incominggoods-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($incoming_goods)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($incoming_goods));
            } else {
                $httpBody = $incoming_goods;
            }
        } 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 voidDocument4
     *
     * Void Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument4'] 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 voidDocument4($id, string $contentType = self::contentTypes['voidDocument4'][0])
    {
        $this->voidDocument4WithHttpInfo($id, $contentType);
    }

    /**
     * Operation voidDocument4WithHttpInfo
     *
     * Void Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument4'] 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 voidDocument4WithHttpInfo($id, string $contentType = self::contentTypes['voidDocument4'][0])
    {
        $request = $this->voidDocument4Request($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 voidDocument4Async
     *
     * Void Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument4'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function voidDocument4Async($id, string $contentType = self::contentTypes['voidDocument4'][0])
    {
        return $this->voidDocument4AsyncWithHttpInfo($id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation voidDocument4AsyncWithHttpInfo
     *
     * Void Incoming Goods document
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument4'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function voidDocument4AsyncWithHttpInfo($id, string $contentType = self::contentTypes['voidDocument4'][0])
    {
        $returnType = '';
        $request = $this->voidDocument4Request($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 'voidDocument4'
     *
     * @param  int $id Incoming goods document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['voidDocument4'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function voidDocument4Request($id, string $contentType = self::contentTypes['voidDocument4'][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 voidDocument4'
            );
        }


        $resourcePath = '/api/warehouse/incominggoods-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;
    }
}
