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

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'addStockTakingRows' => [
            'application/json',
        ],
        'addStockTakingRowsByFilter' => [
            'application/json',
        ],
        'create2' => [
            'application/json',
        ],
        'deleteStockTaking' => [
            'application/json',
        ],
        'deleteStockTakingRow' => [
            'application/json',
        ],
        'deleteStockTakingRowByFilter' => [
            'application/json',
        ],
        'get2' => [
            'application/json',
        ],
        'getAll1' => [
            'application/json',
        ],
        'getCandidateRows' => [
            'application/json',
        ],
        'getRows' => [
            'application/json',
        ],
        'release2' => [
            'application/json',
        ],
        'update2' => [
            'application/json',
        ],
        'voidStockTaking' => [
            '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 addStockTakingRows
     *
     * Add rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTakingRow[]|null $rows A list of &lt;code&gt;StockTakingRows&lt;/code&gt;. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRows'] 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 addStockTakingRows($id, $rows = null, string $contentType = self::contentTypes['addStockTakingRows'][0])
    {
        $this->addStockTakingRowsWithHttpInfo($id, $rows, $contentType);
    }

    /**
     * Operation addStockTakingRowsWithHttpInfo
     *
     * Add rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTakingRow[]|null $rows A list of &lt;code&gt;StockTakingRows&lt;/code&gt;. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRows'] 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 addStockTakingRowsWithHttpInfo($id, $rows = null, string $contentType = self::contentTypes['addStockTakingRows'][0])
    {
        $request = $this->addStockTakingRowsRequest($id, $rows, $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 addStockTakingRowsAsync
     *
     * Add rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTakingRow[]|null $rows A list of &lt;code&gt;StockTakingRows&lt;/code&gt;. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRows'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function addStockTakingRowsAsync($id, $rows = null, string $contentType = self::contentTypes['addStockTakingRows'][0])
    {
        return $this->addStockTakingRowsAsyncWithHttpInfo($id, $rows, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation addStockTakingRowsAsyncWithHttpInfo
     *
     * Add rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTakingRow[]|null $rows A list of &lt;code&gt;StockTakingRows&lt;/code&gt;. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRows'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function addStockTakingRowsAsyncWithHttpInfo($id, $rows = null, string $contentType = self::contentTypes['addStockTakingRows'][0])
    {
        $returnType = '';
        $request = $this->addStockTakingRowsRequest($id, $rows, $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 'addStockTakingRows'
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTakingRow[]|null $rows A list of &lt;code&gt;StockTakingRows&lt;/code&gt;. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRows'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function addStockTakingRowsRequest($id, $rows = null, string $contentType = self::contentTypes['addStockTakingRows'][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 addStockTakingRows'
            );
        }



        $resourcePath = '/api/warehouse/stocktaking-v1/{id}/rows';
        $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($rows)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($rows));
            } else {
                $httpBody = $rows;
            }
        } 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 addStockTakingRowsByFilter
     *
     * Add rows by filter
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids item_ids (optional)
     * @param  string[]|null $supplier_numbers supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date transaction_date (optional)
     * @param  string|null $item_id_search item_id_search (optional)
     * @param  string|null $item_description_search item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items exclude_zero_balance_items (optional)
     * @param  bool|null $exclude_non_inbound_items exclude_non_inbound_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRowsByFilter'] 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 int|\Fortnox\Model\WarehouseWebException
     */
    public function addStockTakingRowsByFilter($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $exclude_non_inbound_items = null, string $contentType = self::contentTypes['addStockTakingRowsByFilter'][0])
    {
        list($response) = $this->addStockTakingRowsByFilterWithHttpInfo($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $exclude_non_inbound_items, $contentType);
        return $response;
    }

    /**
     * Operation addStockTakingRowsByFilterWithHttpInfo
     *
     * Add rows by filter
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  bool|null $exclude_non_inbound_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRowsByFilter'] 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 int|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function addStockTakingRowsByFilterWithHttpInfo($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $exclude_non_inbound_items = null, string $contentType = self::contentTypes['addStockTakingRowsByFilter'][0])
    {
        $request = $this->addStockTakingRowsByFilterRequest($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $exclude_non_inbound_items, $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(
                        'int',
                        $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(
                'int',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'int',
                        $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 addStockTakingRowsByFilterAsync
     *
     * Add rows by filter
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  bool|null $exclude_non_inbound_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRowsByFilter'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function addStockTakingRowsByFilterAsync($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $exclude_non_inbound_items = null, string $contentType = self::contentTypes['addStockTakingRowsByFilter'][0])
    {
        return $this->addStockTakingRowsByFilterAsyncWithHttpInfo($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $exclude_non_inbound_items, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation addStockTakingRowsByFilterAsyncWithHttpInfo
     *
     * Add rows by filter
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  bool|null $exclude_non_inbound_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRowsByFilter'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function addStockTakingRowsByFilterAsyncWithHttpInfo($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $exclude_non_inbound_items = null, string $contentType = self::contentTypes['addStockTakingRowsByFilter'][0])
    {
        $returnType = 'int';
        $request = $this->addStockTakingRowsByFilterRequest($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $exclude_non_inbound_items, $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 'addStockTakingRowsByFilter'
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  bool|null $exclude_non_inbound_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['addStockTakingRowsByFilter'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function addStockTakingRowsByFilterRequest($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $exclude_non_inbound_items = null, string $contentType = self::contentTypes['addStockTakingRowsByFilter'][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 addStockTakingRowsByFilter'
            );
        }











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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_ids,
            'itemIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $supplier_numbers,
            'supplierNumbers', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $stock_point_ids,
            'stockPointIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $stock_location_ids,
            'stockLocationIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transaction_date,
            'transactionDate', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_id_search,
            'itemIdSearch', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_description_search,
            'itemDescriptionSearch', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $exclude_zero_balance_items,
            'excludeZeroBalanceItems', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $exclude_non_inbound_items,
            'excludeNonInboundItems', // param base name
            'boolean', // 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(
            'POST',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation create2
     *
     * Create stock taking
     *
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create2'] 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\WarehouseStockTaking|\Fortnox\Model\WarehouseWebException
     */
    public function create2($stock_taking = null, string $contentType = self::contentTypes['create2'][0])
    {
        list($response) = $this->create2WithHttpInfo($stock_taking, $contentType);
        return $response;
    }

    /**
     * Operation create2WithHttpInfo
     *
     * Create stock taking
     *
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create2'] 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\WarehouseStockTaking|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function create2WithHttpInfo($stock_taking = null, string $contentType = self::contentTypes['create2'][0])
    {
        $request = $this->create2Request($stock_taking, $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\WarehouseStockTaking',
                        $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\WarehouseStockTaking',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseStockTaking',
                        $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 create2Async
     *
     * Create stock taking
     *
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function create2Async($stock_taking = null, string $contentType = self::contentTypes['create2'][0])
    {
        return $this->create2AsyncWithHttpInfo($stock_taking, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation create2AsyncWithHttpInfo
     *
     * Create stock taking
     *
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function create2AsyncWithHttpInfo($stock_taking = null, string $contentType = self::contentTypes['create2'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseStockTaking';
        $request = $this->create2Request($stock_taking, $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 'create2'
     *
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['create2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function create2Request($stock_taking = null, string $contentType = self::contentTypes['create2'][0])
    {



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





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

        // for model (json/xml)
        if (isset($stock_taking)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($stock_taking));
            } else {
                $httpBody = $stock_taking;
            }
        } 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 deleteStockTaking
     *
     * Delete Stock Taking document
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTaking'] 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 deleteStockTaking($id, string $contentType = self::contentTypes['deleteStockTaking'][0])
    {
        $this->deleteStockTakingWithHttpInfo($id, $contentType);
    }

    /**
     * Operation deleteStockTakingWithHttpInfo
     *
     * Delete Stock Taking document
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTaking'] 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 deleteStockTakingWithHttpInfo($id, string $contentType = self::contentTypes['deleteStockTaking'][0])
    {
        $request = $this->deleteStockTakingRequest($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 deleteStockTakingAsync
     *
     * Delete Stock Taking document
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTaking'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteStockTakingAsync($id, string $contentType = self::contentTypes['deleteStockTaking'][0])
    {
        return $this->deleteStockTakingAsyncWithHttpInfo($id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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


        $resourcePath = '/api/warehouse/stocktaking-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 (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(
            'DELETE',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation deleteStockTakingRow
     *
     * Delete row
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $row_id row id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRow'] 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 int|\Fortnox\Model\WarehouseWebException
     */
    public function deleteStockTakingRow($id, $row_id, string $contentType = self::contentTypes['deleteStockTakingRow'][0])
    {
        list($response) = $this->deleteStockTakingRowWithHttpInfo($id, $row_id, $contentType);
        return $response;
    }

    /**
     * Operation deleteStockTakingRowWithHttpInfo
     *
     * Delete row
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $row_id row id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRow'] 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 int|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function deleteStockTakingRowWithHttpInfo($id, $row_id, string $contentType = self::contentTypes['deleteStockTakingRow'][0])
    {
        $request = $this->deleteStockTakingRowRequest($id, $row_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(
                        'int',
                        $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(
                'int',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'int',
                        $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 deleteStockTakingRowAsync
     *
     * Delete row
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $row_id row id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteStockTakingRowAsync($id, $row_id, string $contentType = self::contentTypes['deleteStockTakingRow'][0])
    {
        return $this->deleteStockTakingRowAsyncWithHttpInfo($id, $row_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteStockTakingRowAsyncWithHttpInfo
     *
     * Delete row
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $row_id row id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteStockTakingRowAsyncWithHttpInfo($id, $row_id, string $contentType = self::contentTypes['deleteStockTakingRow'][0])
    {
        $returnType = 'int';
        $request = $this->deleteStockTakingRowRequest($id, $row_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 'deleteStockTakingRow'
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $row_id row id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function deleteStockTakingRowRequest($id, $row_id, string $contentType = self::contentTypes['deleteStockTakingRow'][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 deleteStockTakingRow'
            );
        }

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


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



        // path params
        if ($id !== null) {
            $resourcePath = str_replace(
                '{' . 'id' . '}',
                ObjectSerializer::toPathValue($id),
                $resourcePath
            );
        }
        // path params
        if ($row_id !== null) {
            $resourcePath = str_replace(
                '{' . 'rowId' . '}',
                ObjectSerializer::toPathValue($row_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(
            'DELETE',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation deleteStockTakingRowByFilter
     *
     * Delete rows by filter
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids item_ids (optional)
     * @param  string[]|null $supplier_numbers supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date transaction_date (optional)
     * @param  string|null $item_id_search item_id_search (optional)
     * @param  string|null $item_description_search item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items exclude_zero_balance_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRowByFilter'] 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 int|\Fortnox\Model\WarehouseWebException
     */
    public function deleteStockTakingRowByFilter($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, string $contentType = self::contentTypes['deleteStockTakingRowByFilter'][0])
    {
        list($response) = $this->deleteStockTakingRowByFilterWithHttpInfo($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $contentType);
        return $response;
    }

    /**
     * Operation deleteStockTakingRowByFilterWithHttpInfo
     *
     * Delete rows by filter
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRowByFilter'] 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 int|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function deleteStockTakingRowByFilterWithHttpInfo($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, string $contentType = self::contentTypes['deleteStockTakingRowByFilter'][0])
    {
        $request = $this->deleteStockTakingRowByFilterRequest($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $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(
                        'int',
                        $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(
                'int',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'int',
                        $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 deleteStockTakingRowByFilterAsync
     *
     * Delete rows by filter
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRowByFilter'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteStockTakingRowByFilterAsync($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, string $contentType = self::contentTypes['deleteStockTakingRowByFilter'][0])
    {
        return $this->deleteStockTakingRowByFilterAsyncWithHttpInfo($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteStockTakingRowByFilterAsyncWithHttpInfo
     *
     * Delete rows by filter
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRowByFilter'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteStockTakingRowByFilterAsyncWithHttpInfo($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, string $contentType = self::contentTypes['deleteStockTakingRowByFilter'][0])
    {
        $returnType = 'int';
        $request = $this->deleteStockTakingRowByFilterRequest($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $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 'deleteStockTakingRowByFilter'
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['deleteStockTakingRowByFilter'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function deleteStockTakingRowByFilterRequest($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, string $contentType = self::contentTypes['deleteStockTakingRowByFilter'][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 deleteStockTakingRowByFilter'
            );
        }










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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_ids,
            'itemIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $supplier_numbers,
            'supplierNumbers', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $stock_point_ids,
            'stockPointIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $stock_location_ids,
            'stockLocationIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transaction_date,
            'transactionDate', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_id_search,
            'itemIdSearch', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_description_search,
            'itemDescriptionSearch', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $exclude_zero_balance_items,
            'excludeZeroBalanceItems', // param base name
            'boolean', // 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(
            'DELETE',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation get2
     *
     * Get Stock Taking document
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get2'] 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\WarehouseStockTaking|\Fortnox\Model\WarehouseWebException
     */
    public function get2($id, string $contentType = self::contentTypes['get2'][0])
    {
        list($response) = $this->get2WithHttpInfo($id, $contentType);
        return $response;
    }

    /**
     * Operation get2WithHttpInfo
     *
     * Get Stock Taking document
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get2'] 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\WarehouseStockTaking|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function get2WithHttpInfo($id, string $contentType = self::contentTypes['get2'][0])
    {
        $request = $this->get2Request($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\WarehouseStockTaking',
                        $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\WarehouseStockTaking',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseStockTaking',
                        $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 get2Async
     *
     * Get Stock Taking document
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['get2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function get2Async($id, string $contentType = self::contentTypes['get2'][0])
    {
        return $this->get2AsyncWithHttpInfo($id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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


        $resourcePath = '/api/warehouse/stocktaking-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 (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 getAll1
     *
     * List stock takings
     *
     * @param  string|null $state Include only stock takings with the given state. (optional)
     * @param  string|null $item_id Include only stock takings with the given item. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll1'] 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\WarehouseStockTaking|\Fortnox\Model\WarehouseWebException
     */
    public function getAll1($state = null, $item_id = null, string $contentType = self::contentTypes['getAll1'][0])
    {
        list($response) = $this->getAll1WithHttpInfo($state, $item_id, $contentType);
        return $response;
    }

    /**
     * Operation getAll1WithHttpInfo
     *
     * List stock takings
     *
     * @param  string|null $state Include only stock takings with the given state. (optional)
     * @param  string|null $item_id Include only stock takings with the given item. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll1'] 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\WarehouseStockTaking|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function getAll1WithHttpInfo($state = null, $item_id = null, string $contentType = self::contentTypes['getAll1'][0])
    {
        $request = $this->getAll1Request($state, $item_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\WarehouseStockTaking',
                        $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\WarehouseStockTaking',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseStockTaking',
                        $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 getAll1Async
     *
     * List stock takings
     *
     * @param  string|null $state Include only stock takings with the given state. (optional)
     * @param  string|null $item_id Include only stock takings with the given item. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll1'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAll1Async($state = null, $item_id = null, string $contentType = self::contentTypes['getAll1'][0])
    {
        return $this->getAll1AsyncWithHttpInfo($state, $item_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getAll1AsyncWithHttpInfo
     *
     * List stock takings
     *
     * @param  string|null $state Include only stock takings with the given state. (optional)
     * @param  string|null $item_id Include only stock takings with the given item. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll1'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getAll1AsyncWithHttpInfo($state = null, $item_id = null, string $contentType = self::contentTypes['getAll1'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseStockTaking';
        $request = $this->getAll1Request($state, $item_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 'getAll1'
     *
     * @param  string|null $state Include only stock takings with the given state. (optional)
     * @param  string|null $item_id Include only stock takings with the given item. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getAll1'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getAll1Request($state = null, $item_id = null, string $contentType = self::contentTypes['getAll1'][0])
    {




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

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




        $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 getCandidateRows
     *
     * Get candidate rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids item_ids (optional)
     * @param  string[]|null $supplier_numbers supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date transaction_date (optional)
     * @param  string|null $item_id_search item_id_search (optional)
     * @param  string|null $item_description_search item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items exclude_zero_balance_items (optional)
     * @param  bool|null $include_non_inbound_items Include items that do not exist on inbound deliveries. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCandidateRows'] 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\WarehouseStockTakingRow|\Fortnox\Model\WarehouseWebException
     */
    public function getCandidateRows($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $include_non_inbound_items = null, string $contentType = self::contentTypes['getCandidateRows'][0])
    {
        list($response) = $this->getCandidateRowsWithHttpInfo($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $include_non_inbound_items, $contentType);
        return $response;
    }

    /**
     * Operation getCandidateRowsWithHttpInfo
     *
     * Get candidate rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  bool|null $include_non_inbound_items Include items that do not exist on inbound deliveries. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCandidateRows'] 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\WarehouseStockTakingRow|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCandidateRowsWithHttpInfo($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $include_non_inbound_items = null, string $contentType = self::contentTypes['getCandidateRows'][0])
    {
        $request = $this->getCandidateRowsRequest($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $include_non_inbound_items, $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\WarehouseStockTakingRow',
                        $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\WarehouseStockTakingRow',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseStockTakingRow',
                        $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 getCandidateRowsAsync
     *
     * Get candidate rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  bool|null $include_non_inbound_items Include items that do not exist on inbound deliveries. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCandidateRows'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCandidateRowsAsync($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $include_non_inbound_items = null, string $contentType = self::contentTypes['getCandidateRows'][0])
    {
        return $this->getCandidateRowsAsyncWithHttpInfo($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $include_non_inbound_items, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCandidateRowsAsyncWithHttpInfo
     *
     * Get candidate rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  bool|null $include_non_inbound_items Include items that do not exist on inbound deliveries. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCandidateRows'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCandidateRowsAsyncWithHttpInfo($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $include_non_inbound_items = null, string $contentType = self::contentTypes['getCandidateRows'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseStockTakingRow';
        $request = $this->getCandidateRowsRequest($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $include_non_inbound_items, $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 'getCandidateRows'
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  bool|null $include_non_inbound_items Include items that do not exist on inbound deliveries. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getCandidateRows'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCandidateRowsRequest($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $include_non_inbound_items = null, string $contentType = self::contentTypes['getCandidateRows'][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 getCandidateRows'
            );
        }











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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_ids,
            'itemIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $supplier_numbers,
            'supplierNumbers', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $stock_point_ids,
            'stockPointIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $stock_location_ids,
            'stockLocationIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transaction_date,
            'transactionDate', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_id_search,
            'itemIdSearch', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_description_search,
            'itemDescriptionSearch', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $exclude_zero_balance_items,
            'excludeZeroBalanceItems', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $include_non_inbound_items,
            'includeNonInboundItems', // param base name
            'boolean', // 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 getRows
     *
     * Get Stock Taking Rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids item_ids (optional)
     * @param  string[]|null $supplier_numbers supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date transaction_date (optional)
     * @param  string|null $item_id_search item_id_search (optional)
     * @param  string|null $item_description_search item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items exclude_zero_balance_items (optional)
     * @param  string|null $secondarysortby Secondary sorting column (optional)
     * @param  string|null $secondaryorder Secondary sorting order (optional)
     * @param  string|null $state_filter state_filter (optional)
     * @param  int|null $starting_row_no the row number to start the search from, used with startingItemId to jump to specific rows, can be empty (optional)
     * @param  string|null $starting_item_id the itemId that should be on top of the rows list (used to jump to specific row), can be empty (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getRows'] 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\WarehouseStockTakingRow|\Fortnox\Model\WarehouseWebException
     */
    public function getRows($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $secondarysortby = null, $secondaryorder = null, $state_filter = null, $starting_row_no = null, $starting_item_id = null, string $contentType = self::contentTypes['getRows'][0])
    {
        list($response) = $this->getRowsWithHttpInfo($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $secondarysortby, $secondaryorder, $state_filter, $starting_row_no, $starting_item_id, $contentType);
        return $response;
    }

    /**
     * Operation getRowsWithHttpInfo
     *
     * Get Stock Taking Rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  string|null $secondarysortby Secondary sorting column (optional)
     * @param  string|null $secondaryorder Secondary sorting order (optional)
     * @param  string|null $state_filter (optional)
     * @param  int|null $starting_row_no the row number to start the search from, used with startingItemId to jump to specific rows, can be empty (optional)
     * @param  string|null $starting_item_id the itemId that should be on top of the rows list (used to jump to specific row), can be empty (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getRows'] 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\WarehouseStockTakingRow|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function getRowsWithHttpInfo($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $secondarysortby = null, $secondaryorder = null, $state_filter = null, $starting_row_no = null, $starting_item_id = null, string $contentType = self::contentTypes['getRows'][0])
    {
        $request = $this->getRowsRequest($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $secondarysortby, $secondaryorder, $state_filter, $starting_row_no, $starting_item_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\WarehouseStockTakingRow',
                        $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\WarehouseStockTakingRow',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseStockTakingRow',
                        $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 getRowsAsync
     *
     * Get Stock Taking Rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  string|null $secondarysortby Secondary sorting column (optional)
     * @param  string|null $secondaryorder Secondary sorting order (optional)
     * @param  string|null $state_filter (optional)
     * @param  int|null $starting_row_no the row number to start the search from, used with startingItemId to jump to specific rows, can be empty (optional)
     * @param  string|null $starting_item_id the itemId that should be on top of the rows list (used to jump to specific row), can be empty (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getRows'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getRowsAsync($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $secondarysortby = null, $secondaryorder = null, $state_filter = null, $starting_row_no = null, $starting_item_id = null, string $contentType = self::contentTypes['getRows'][0])
    {
        return $this->getRowsAsyncWithHttpInfo($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $secondarysortby, $secondaryorder, $state_filter, $starting_row_no, $starting_item_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getRowsAsyncWithHttpInfo
     *
     * Get Stock Taking Rows
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  string|null $secondarysortby Secondary sorting column (optional)
     * @param  string|null $secondaryorder Secondary sorting order (optional)
     * @param  string|null $state_filter (optional)
     * @param  int|null $starting_row_no the row number to start the search from, used with startingItemId to jump to specific rows, can be empty (optional)
     * @param  string|null $starting_item_id the itemId that should be on top of the rows list (used to jump to specific row), can be empty (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getRows'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getRowsAsyncWithHttpInfo($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $secondarysortby = null, $secondaryorder = null, $state_filter = null, $starting_row_no = null, $starting_item_id = null, string $contentType = self::contentTypes['getRows'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseStockTakingRow';
        $request = $this->getRowsRequest($id, $item_ids, $supplier_numbers, $stock_point_ids, $stock_location_ids, $transaction_date, $item_id_search, $item_description_search, $exclude_zero_balance_items, $secondarysortby, $secondaryorder, $state_filter, $starting_row_no, $starting_item_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 'getRows'
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string[]|null $item_ids (optional)
     * @param  string[]|null $supplier_numbers (optional)
     * @param  string[]|null $stock_point_ids (optional)
     * @param  string[]|null $stock_location_ids (optional)
     * @param  \DateTime|null $transaction_date (optional)
     * @param  string|null $item_id_search (optional)
     * @param  string|null $item_description_search (optional)
     * @param  bool|null $exclude_zero_balance_items (optional)
     * @param  string|null $secondarysortby Secondary sorting column (optional)
     * @param  string|null $secondaryorder Secondary sorting order (optional)
     * @param  string|null $state_filter (optional)
     * @param  int|null $starting_row_no the row number to start the search from, used with startingItemId to jump to specific rows, can be empty (optional)
     * @param  string|null $starting_item_id the itemId that should be on top of the rows list (used to jump to specific row), can be empty (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getRows'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getRowsRequest($id, $item_ids = null, $supplier_numbers = null, $stock_point_ids = null, $stock_location_ids = null, $transaction_date = null, $item_id_search = null, $item_description_search = null, $exclude_zero_balance_items = null, $secondarysortby = null, $secondaryorder = null, $state_filter = null, $starting_row_no = null, $starting_item_id = null, string $contentType = self::contentTypes['getRows'][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 getRows'
            );
        }















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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_ids,
            'itemIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $supplier_numbers,
            'supplierNumbers', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $stock_point_ids,
            'stockPointIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $stock_location_ids,
            'stockLocationIds', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transaction_date,
            'transactionDate', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_id_search,
            'itemIdSearch', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $item_description_search,
            'itemDescriptionSearch', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $exclude_zero_balance_items,
            'excludeZeroBalanceItems', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $secondarysortby,
            'secondarysortby', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $secondaryorder,
            'secondaryorder', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $state_filter,
            'stateFilter', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $starting_row_no,
            'startingRowNo', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $starting_item_id,
            'startingItemId', // param base name
            'string', // 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 release2
     *
     * Release Stock Taking document
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['release2'] 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 release2($id, string $contentType = self::contentTypes['release2'][0])
    {
        $this->release2WithHttpInfo($id, $contentType);
    }

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

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


        $resourcePath = '/api/warehouse/stocktaking-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 update2
     *
     * Update a stock taking
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update2'] 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\WarehouseStockTaking|\Fortnox\Model\WarehouseWebException
     */
    public function update2($id, $stock_taking = null, string $contentType = self::contentTypes['update2'][0])
    {
        list($response) = $this->update2WithHttpInfo($id, $stock_taking, $contentType);
        return $response;
    }

    /**
     * Operation update2WithHttpInfo
     *
     * Update a stock taking
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update2'] 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\WarehouseStockTaking|\Fortnox\Model\WarehouseWebException, HTTP status code, HTTP response headers (array of strings)
     */
    public function update2WithHttpInfo($id, $stock_taking = null, string $contentType = self::contentTypes['update2'][0])
    {
        $request = $this->update2Request($id, $stock_taking, $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\WarehouseStockTaking',
                        $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\WarehouseStockTaking',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\WarehouseStockTaking',
                        $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 update2Async
     *
     * Update a stock taking
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function update2Async($id, $stock_taking = null, string $contentType = self::contentTypes['update2'][0])
    {
        return $this->update2AsyncWithHttpInfo($id, $stock_taking, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation update2AsyncWithHttpInfo
     *
     * Update a stock taking
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function update2AsyncWithHttpInfo($id, $stock_taking = null, string $contentType = self::contentTypes['update2'][0])
    {
        $returnType = '\Fortnox\Model\WarehouseStockTaking';
        $request = $this->update2Request($id, $stock_taking, $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 'update2'
     *
     * @param  int $id Stock Taking document id. (required)
     * @param  \Fortnox\Model\WarehouseStockTaking|null $stock_taking stock taking (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['update2'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function update2Request($id, $stock_taking = null, string $contentType = self::contentTypes['update2'][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 update2'
            );
        }



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

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

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


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