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

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'supplierInvoiceControllerDoCreate' => [
            'application/json',
        ],
        'supplierInvoiceControllerDoIndex' => [
            'application/json',
        ],
        'supplierInvoiceControllerDoShow' => [
            'application/json',
        ],
        'supplierInvoiceControllerDoUpdate' => [
            'application/json',
        ],
        'supplierInvoiceControllerDoUpdateAndApprovalBookkeep' => [
            'application/json',
        ],
        'supplierInvoiceControllerDoUpdateAndApprovalPayment' => [
            'application/json',
        ],
        'supplierInvoiceControllerDoUpdateAndBookkeep' => [
            'application/json',
        ],
        'supplierInvoiceControllerDoUpdateAndCancel' => [
            'application/json',
        ],
        'supplierInvoiceControllerDoUpdateAndCredit' => [
            '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 supplierInvoiceControllerDoCreate
     *
     * Create a supplier invoice
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for create supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoCreate'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoiceControllerDoCreate($supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoCreate'][0])
    {
        list($response) = $this->supplierInvoiceControllerDoCreateWithHttpInfo($supplier_invoice, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoiceControllerDoCreateWithHttpInfo
     *
     * Create a supplier invoice
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for create supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoCreate'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoiceControllerDoCreateWithHttpInfo($supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoCreate'][0])
    {
        $request = $this->supplierInvoiceControllerDoCreateRequest($supplier_invoice, $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation supplierInvoiceControllerDoCreateAsync
     *
     * Create a supplier invoice
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for create supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoCreateAsync($supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoCreate'][0])
    {
        return $this->supplierInvoiceControllerDoCreateAsyncWithHttpInfo($supplier_invoice, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoiceControllerDoCreateAsyncWithHttpInfo
     *
     * Create a supplier invoice
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for create supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoCreateAsyncWithHttpInfo($supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoCreate'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap';
        $request = $this->supplierInvoiceControllerDoCreateRequest($supplier_invoice, $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 'supplierInvoiceControllerDoCreate'
     *
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for create supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoiceControllerDoCreateRequest($supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoCreate'][0])
    {



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





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

        // for model (json/xml)
        if (isset($supplier_invoice)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($supplier_invoice));
            } else {
                $httpBody = $supplier_invoice;
            }
        } 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 supplierInvoiceControllerDoIndex
     *
     * Retrieve a list of supplier invoices
     *
     * @param  \DateTime|null $tofinalpaydate Filter supplier invoices by final to pay date (optional)
     * @param  \DateTime|null $fromfinalpaydate Filter supplier invoices by final from pay date (optional)
     * @param  string|null $filter Filter supplier invoices by status (optional)
     * @param  \DateTime|null $lastmodified Filter supplier invoices by last modified date (optional)
     * @param  string|null $suppliernumber Filter supplier invoices by supplier number (optional)
     * @param  string|null $suppliername Filter supplier invoices by supplier name (optional)
     * @param  string|null $ocr Filter supplier invoices by ocr number (optional)
     * @param  string|null $invoicenumber Filter supplier invoices by invoice number (optional)
     * @param  string|null $serialnumber Filter supplier invoices by serial number (optional)
     * @param  string|null $costcenter Filter supplier invoices by cost center (optional)
     * @param  string|null $project Filter supplier invoices by project (optional)
     * @param  string|null $ourreference Filter supplier invoices by our reference (optional)
     * @param  string|null $yourreference Filter supplier invoices by your reference (optional)
     * @param  \DateTime|null $fromdate Filter supplier invoices by from date (optional)
     * @param  \DateTime|null $todate Filter supplier invoices by to date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoIndex'] 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\FortnoxLfSupplierInvoiceListItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoiceControllerDoIndex($tofinalpaydate = null, $fromfinalpaydate = null, $filter = null, $lastmodified = null, $suppliernumber = null, $suppliername = null, $ocr = null, $invoicenumber = null, $serialnumber = null, $costcenter = null, $project = null, $ourreference = null, $yourreference = null, $fromdate = null, $todate = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoIndex'][0])
    {
        list($response) = $this->supplierInvoiceControllerDoIndexWithHttpInfo($tofinalpaydate, $fromfinalpaydate, $filter, $lastmodified, $suppliernumber, $suppliername, $ocr, $invoicenumber, $serialnumber, $costcenter, $project, $ourreference, $yourreference, $fromdate, $todate, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoiceControllerDoIndexWithHttpInfo
     *
     * Retrieve a list of supplier invoices
     *
     * @param  \DateTime|null $tofinalpaydate Filter supplier invoices by final to pay date (optional)
     * @param  \DateTime|null $fromfinalpaydate Filter supplier invoices by final from pay date (optional)
     * @param  string|null $filter Filter supplier invoices by status (optional)
     * @param  \DateTime|null $lastmodified Filter supplier invoices by last modified date (optional)
     * @param  string|null $suppliernumber Filter supplier invoices by supplier number (optional)
     * @param  string|null $suppliername Filter supplier invoices by supplier name (optional)
     * @param  string|null $ocr Filter supplier invoices by ocr number (optional)
     * @param  string|null $invoicenumber Filter supplier invoices by invoice number (optional)
     * @param  string|null $serialnumber Filter supplier invoices by serial number (optional)
     * @param  string|null $costcenter Filter supplier invoices by cost center (optional)
     * @param  string|null $project Filter supplier invoices by project (optional)
     * @param  string|null $ourreference Filter supplier invoices by our reference (optional)
     * @param  string|null $yourreference Filter supplier invoices by your reference (optional)
     * @param  \DateTime|null $fromdate Filter supplier invoices by from date (optional)
     * @param  \DateTime|null $todate Filter supplier invoices by to date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoIndex'] 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\FortnoxLfSupplierInvoiceListItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoiceControllerDoIndexWithHttpInfo($tofinalpaydate = null, $fromfinalpaydate = null, $filter = null, $lastmodified = null, $suppliernumber = null, $suppliername = null, $ocr = null, $invoicenumber = null, $serialnumber = null, $costcenter = null, $project = null, $ourreference = null, $yourreference = null, $fromdate = null, $todate = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoIndex'][0])
    {
        $request = $this->supplierInvoiceControllerDoIndexRequest($tofinalpaydate, $fromfinalpaydate, $filter, $lastmodified, $suppliernumber, $suppliername, $ocr, $invoicenumber, $serialnumber, $costcenter, $project, $ourreference, $yourreference, $fromdate, $todate, $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\FortnoxLfSupplierInvoiceListItemWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $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\FortnoxLfSupplierInvoiceListItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoiceListItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation supplierInvoiceControllerDoIndexAsync
     *
     * Retrieve a list of supplier invoices
     *
     * @param  \DateTime|null $tofinalpaydate Filter supplier invoices by final to pay date (optional)
     * @param  \DateTime|null $fromfinalpaydate Filter supplier invoices by final from pay date (optional)
     * @param  string|null $filter Filter supplier invoices by status (optional)
     * @param  \DateTime|null $lastmodified Filter supplier invoices by last modified date (optional)
     * @param  string|null $suppliernumber Filter supplier invoices by supplier number (optional)
     * @param  string|null $suppliername Filter supplier invoices by supplier name (optional)
     * @param  string|null $ocr Filter supplier invoices by ocr number (optional)
     * @param  string|null $invoicenumber Filter supplier invoices by invoice number (optional)
     * @param  string|null $serialnumber Filter supplier invoices by serial number (optional)
     * @param  string|null $costcenter Filter supplier invoices by cost center (optional)
     * @param  string|null $project Filter supplier invoices by project (optional)
     * @param  string|null $ourreference Filter supplier invoices by our reference (optional)
     * @param  string|null $yourreference Filter supplier invoices by your reference (optional)
     * @param  \DateTime|null $fromdate Filter supplier invoices by from date (optional)
     * @param  \DateTime|null $todate Filter supplier invoices by to date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoIndexAsync($tofinalpaydate = null, $fromfinalpaydate = null, $filter = null, $lastmodified = null, $suppliernumber = null, $suppliername = null, $ocr = null, $invoicenumber = null, $serialnumber = null, $costcenter = null, $project = null, $ourreference = null, $yourreference = null, $fromdate = null, $todate = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoIndex'][0])
    {
        return $this->supplierInvoiceControllerDoIndexAsyncWithHttpInfo($tofinalpaydate, $fromfinalpaydate, $filter, $lastmodified, $suppliernumber, $suppliername, $ocr, $invoicenumber, $serialnumber, $costcenter, $project, $ourreference, $yourreference, $fromdate, $todate, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoiceControllerDoIndexAsyncWithHttpInfo
     *
     * Retrieve a list of supplier invoices
     *
     * @param  \DateTime|null $tofinalpaydate Filter supplier invoices by final to pay date (optional)
     * @param  \DateTime|null $fromfinalpaydate Filter supplier invoices by final from pay date (optional)
     * @param  string|null $filter Filter supplier invoices by status (optional)
     * @param  \DateTime|null $lastmodified Filter supplier invoices by last modified date (optional)
     * @param  string|null $suppliernumber Filter supplier invoices by supplier number (optional)
     * @param  string|null $suppliername Filter supplier invoices by supplier name (optional)
     * @param  string|null $ocr Filter supplier invoices by ocr number (optional)
     * @param  string|null $invoicenumber Filter supplier invoices by invoice number (optional)
     * @param  string|null $serialnumber Filter supplier invoices by serial number (optional)
     * @param  string|null $costcenter Filter supplier invoices by cost center (optional)
     * @param  string|null $project Filter supplier invoices by project (optional)
     * @param  string|null $ourreference Filter supplier invoices by our reference (optional)
     * @param  string|null $yourreference Filter supplier invoices by your reference (optional)
     * @param  \DateTime|null $fromdate Filter supplier invoices by from date (optional)
     * @param  \DateTime|null $todate Filter supplier invoices by to date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoIndexAsyncWithHttpInfo($tofinalpaydate = null, $fromfinalpaydate = null, $filter = null, $lastmodified = null, $suppliernumber = null, $suppliername = null, $ocr = null, $invoicenumber = null, $serialnumber = null, $costcenter = null, $project = null, $ourreference = null, $yourreference = null, $fromdate = null, $todate = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoIndex'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoiceListItemWrap';
        $request = $this->supplierInvoiceControllerDoIndexRequest($tofinalpaydate, $fromfinalpaydate, $filter, $lastmodified, $suppliernumber, $suppliername, $ocr, $invoicenumber, $serialnumber, $costcenter, $project, $ourreference, $yourreference, $fromdate, $todate, $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 'supplierInvoiceControllerDoIndex'
     *
     * @param  \DateTime|null $tofinalpaydate Filter supplier invoices by final to pay date (optional)
     * @param  \DateTime|null $fromfinalpaydate Filter supplier invoices by final from pay date (optional)
     * @param  string|null $filter Filter supplier invoices by status (optional)
     * @param  \DateTime|null $lastmodified Filter supplier invoices by last modified date (optional)
     * @param  string|null $suppliernumber Filter supplier invoices by supplier number (optional)
     * @param  string|null $suppliername Filter supplier invoices by supplier name (optional)
     * @param  string|null $ocr Filter supplier invoices by ocr number (optional)
     * @param  string|null $invoicenumber Filter supplier invoices by invoice number (optional)
     * @param  string|null $serialnumber Filter supplier invoices by serial number (optional)
     * @param  string|null $costcenter Filter supplier invoices by cost center (optional)
     * @param  string|null $project Filter supplier invoices by project (optional)
     * @param  string|null $ourreference Filter supplier invoices by our reference (optional)
     * @param  string|null $yourreference Filter supplier invoices by your reference (optional)
     * @param  \DateTime|null $fromdate Filter supplier invoices by from date (optional)
     * @param  \DateTime|null $todate Filter supplier invoices by to date (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoiceControllerDoIndexRequest($tofinalpaydate = null, $fromfinalpaydate = null, $filter = null, $lastmodified = null, $suppliernumber = null, $suppliername = null, $ocr = null, $invoicenumber = null, $serialnumber = null, $costcenter = null, $project = null, $ourreference = null, $yourreference = null, $fromdate = null, $todate = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoIndex'][0])
    {

















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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $tofinalpaydate,
            'tofinalpaydate', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fromfinalpaydate,
            'fromfinalpaydate', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $filter,
            'filter', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $lastmodified,
            'lastmodified', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $suppliernumber,
            'suppliernumber', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $suppliername,
            'suppliername', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $ocr,
            'ocr', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $invoicenumber,
            'invoicenumber', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $serialnumber,
            'serialnumber', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $costcenter,
            'costcenter', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $project,
            'project', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $ourreference,
            'ourreference', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $yourreference,
            'yourreference', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fromdate,
            'fromdate', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $todate,
            'todate', // 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 supplierInvoiceControllerDoShow
     *
     * Retrieve a single supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoShow'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoiceControllerDoShow($given_number, string $contentType = self::contentTypes['supplierInvoiceControllerDoShow'][0])
    {
        list($response) = $this->supplierInvoiceControllerDoShowWithHttpInfo($given_number, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoiceControllerDoShowWithHttpInfo
     *
     * Retrieve a single supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoShow'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoiceControllerDoShowWithHttpInfo($given_number, string $contentType = self::contentTypes['supplierInvoiceControllerDoShow'][0])
    {
        $request = $this->supplierInvoiceControllerDoShowRequest($given_number, $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation supplierInvoiceControllerDoShowAsync
     *
     * Retrieve a single supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoShowAsync($given_number, string $contentType = self::contentTypes['supplierInvoiceControllerDoShow'][0])
    {
        return $this->supplierInvoiceControllerDoShowAsyncWithHttpInfo($given_number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoiceControllerDoShowAsyncWithHttpInfo
     *
     * Retrieve a single supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoShowAsyncWithHttpInfo($given_number, string $contentType = self::contentTypes['supplierInvoiceControllerDoShow'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap';
        $request = $this->supplierInvoiceControllerDoShowRequest($given_number, $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 'supplierInvoiceControllerDoShow'
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoiceControllerDoShowRequest($given_number, string $contentType = self::contentTypes['supplierInvoiceControllerDoShow'][0])
    {

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


        $resourcePath = '/3/supplierinvoices/{GivenNumber}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // path params
        if ($given_number !== null) {
            $resourcePath = str_replace(
                '{' . 'GivenNumber' . '}',
                ObjectSerializer::toPathValue($given_number),
                $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 supplierInvoiceControllerDoUpdate
     *
     * Update a supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdate'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoiceControllerDoUpdate($given_number, $supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdate'][0])
    {
        list($response) = $this->supplierInvoiceControllerDoUpdateWithHttpInfo($given_number, $supplier_invoice, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateWithHttpInfo
     *
     * Update a supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdate'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoiceControllerDoUpdateWithHttpInfo($given_number, $supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdate'][0])
    {
        $request = $this->supplierInvoiceControllerDoUpdateRequest($given_number, $supplier_invoice, $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAsync
     *
     * Update a supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAsync($given_number, $supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdate'][0])
    {
        return $this->supplierInvoiceControllerDoUpdateAsyncWithHttpInfo($given_number, $supplier_invoice, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAsyncWithHttpInfo
     *
     * Update a supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAsyncWithHttpInfo($given_number, $supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdate'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap';
        $request = $this->supplierInvoiceControllerDoUpdateRequest($given_number, $supplier_invoice, $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 'supplierInvoiceControllerDoUpdate'
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $supplier_invoice Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoiceControllerDoUpdateRequest($given_number, $supplier_invoice = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdate'][0])
    {

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



        $resourcePath = '/3/supplierinvoices/{GivenNumber}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($supplier_invoice)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($supplier_invoice));
            } else {
                $httpBody = $supplier_invoice;
            }
        } 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 supplierInvoiceControllerDoUpdateAndApprovalBookkeep
     *
     * Approval of bookkeep of given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalBookkeep($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'][0])
    {
        list($response) = $this->supplierInvoiceControllerDoUpdateAndApprovalBookkeepWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndApprovalBookkeepWithHttpInfo
     *
     * Approval of bookkeep of given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalBookkeepWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'][0])
    {
        $request = $this->supplierInvoiceControllerDoUpdateAndApprovalBookkeepRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndApprovalBookkeepAsync
     *
     * Approval of bookkeep of given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalBookkeepAsync($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'][0])
    {
        return $this->supplierInvoiceControllerDoUpdateAndApprovalBookkeepAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndApprovalBookkeepAsyncWithHttpInfo
     *
     * Approval of bookkeep of given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalBookkeepAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap';
        $request = $this->supplierInvoiceControllerDoUpdateAndApprovalBookkeepRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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 'supplierInvoiceControllerDoUpdateAndApprovalBookkeep'
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalBookkeepRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalBookkeep'][0])
    {

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



        $resourcePath = '/3/supplierinvoices/{GivenNumber}/approvalbookkeep';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($fortnox_lf_supplier_invoice_single_payload_item_wrap)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($fortnox_lf_supplier_invoice_single_payload_item_wrap));
            } else {
                $httpBody = $fortnox_lf_supplier_invoice_single_payload_item_wrap;
            }
        } 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 supplierInvoiceControllerDoUpdateAndApprovalPayment
     *
     * Approval of payment of given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalPayment($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'][0])
    {
        list($response) = $this->supplierInvoiceControllerDoUpdateAndApprovalPaymentWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndApprovalPaymentWithHttpInfo
     *
     * Approval of payment of given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalPaymentWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'][0])
    {
        $request = $this->supplierInvoiceControllerDoUpdateAndApprovalPaymentRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndApprovalPaymentAsync
     *
     * Approval of payment of given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalPaymentAsync($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'][0])
    {
        return $this->supplierInvoiceControllerDoUpdateAndApprovalPaymentAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndApprovalPaymentAsyncWithHttpInfo
     *
     * Approval of payment of given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalPaymentAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap';
        $request = $this->supplierInvoiceControllerDoUpdateAndApprovalPaymentRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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 'supplierInvoiceControllerDoUpdateAndApprovalPayment'
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoiceControllerDoUpdateAndApprovalPaymentRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndApprovalPayment'][0])
    {

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



        $resourcePath = '/3/supplierinvoices/{GivenNumber}/approvalpayment';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($fortnox_lf_supplier_invoice_single_payload_item_wrap)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($fortnox_lf_supplier_invoice_single_payload_item_wrap));
            } else {
                $httpBody = $fortnox_lf_supplier_invoice_single_payload_item_wrap;
            }
        } 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 supplierInvoiceControllerDoUpdateAndBookkeep
     *
     * Bookkeep given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoiceControllerDoUpdateAndBookkeep($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'][0])
    {
        list($response) = $this->supplierInvoiceControllerDoUpdateAndBookkeepWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndBookkeepWithHttpInfo
     *
     * Bookkeep given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoiceControllerDoUpdateAndBookkeepWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'][0])
    {
        $request = $this->supplierInvoiceControllerDoUpdateAndBookkeepRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndBookkeepAsync
     *
     * Bookkeep given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndBookkeepAsync($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'][0])
    {
        return $this->supplierInvoiceControllerDoUpdateAndBookkeepAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndBookkeepAsyncWithHttpInfo
     *
     * Bookkeep given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndBookkeepAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap';
        $request = $this->supplierInvoiceControllerDoUpdateAndBookkeepRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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 'supplierInvoiceControllerDoUpdateAndBookkeep'
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoiceControllerDoUpdateAndBookkeepRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndBookkeep'][0])
    {

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



        $resourcePath = '/3/supplierinvoices/{GivenNumber}/bookkeep';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($fortnox_lf_supplier_invoice_single_payload_item_wrap)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($fortnox_lf_supplier_invoice_single_payload_item_wrap));
            } else {
                $httpBody = $fortnox_lf_supplier_invoice_single_payload_item_wrap;
            }
        } 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 supplierInvoiceControllerDoUpdateAndCancel
     *
     * Cancels given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoiceControllerDoUpdateAndCancel($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'][0])
    {
        list($response) = $this->supplierInvoiceControllerDoUpdateAndCancelWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndCancelWithHttpInfo
     *
     * Cancels given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoiceControllerDoUpdateAndCancelWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'][0])
    {
        $request = $this->supplierInvoiceControllerDoUpdateAndCancelRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndCancelAsync
     *
     * Cancels given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndCancelAsync($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'][0])
    {
        return $this->supplierInvoiceControllerDoUpdateAndCancelAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndCancelAsyncWithHttpInfo
     *
     * Cancels given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndCancelAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap';
        $request = $this->supplierInvoiceControllerDoUpdateAndCancelRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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 'supplierInvoiceControllerDoUpdateAndCancel'
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoiceControllerDoUpdateAndCancelRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCancel'][0])
    {

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



        $resourcePath = '/3/supplierinvoices/{GivenNumber}/cancel';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($fortnox_lf_supplier_invoice_single_payload_item_wrap)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($fortnox_lf_supplier_invoice_single_payload_item_wrap));
            } else {
                $httpBody = $fortnox_lf_supplier_invoice_single_payload_item_wrap;
            }
        } 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 supplierInvoiceControllerDoUpdateAndCredit
     *
     * Credit given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function supplierInvoiceControllerDoUpdateAndCredit($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'][0])
    {
        list($response) = $this->supplierInvoiceControllerDoUpdateAndCreditWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType);
        return $response;
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndCreditWithHttpInfo
     *
     * Credit given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'] 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\FortnoxLfSupplierInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function supplierInvoiceControllerDoUpdateAndCreditWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'][0])
    {
        $request = $this->supplierInvoiceControllerDoUpdateAndCreditRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $request,
                        $response,
                    );
                case 400:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $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\FortnoxLfSupplierInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndCreditAsync
     *
     * Credit given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndCreditAsync($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'][0])
    {
        return $this->supplierInvoiceControllerDoUpdateAndCreditAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation supplierInvoiceControllerDoUpdateAndCreditAsyncWithHttpInfo
     *
     * Credit given supplier invoice
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function supplierInvoiceControllerDoUpdateAndCreditAsyncWithHttpInfo($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxLfSupplierInvoiceSingleItemWrap';
        $request = $this->supplierInvoiceControllerDoUpdateAndCreditRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap, $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 'supplierInvoiceControllerDoUpdateAndCredit'
     *
     * @param  int $given_number identifies the invoice (required)
     * @param  \Fortnox\Model\FortnoxLfSupplierInvoiceSinglePayloadItemWrap|null $fortnox_lf_supplier_invoice_single_payload_item_wrap Request body for update supplier invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function supplierInvoiceControllerDoUpdateAndCreditRequest($given_number, $fortnox_lf_supplier_invoice_single_payload_item_wrap = null, string $contentType = self::contentTypes['supplierInvoiceControllerDoUpdateAndCredit'][0])
    {

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



        $resourcePath = '/3/supplierinvoices/{GivenNumber}/credit';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

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

    /**
     * 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;
    }
}
