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

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'noxInvoiceControllerDoCreate' => [
            'application/json',
        ],
        'noxInvoiceControllerDoShow' => [
            'application/json',
        ],
        'noxInvoiceControllerDoUpdateAndPause' => [
            'application/json',
        ],
        'noxInvoiceControllerDoUpdateAndRepostPayment' => [
            'application/json',
        ],
        'noxInvoiceControllerDoUpdateAndStop' => [
            'application/json',
        ],
        'noxInvoiceControllerDoUpdateAndTakeFees' => [
            'application/json',
        ],
        'noxInvoiceControllerDoUpdateAndUnpause' => [
            '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 noxInvoiceControllerDoCreate
     *
     * Send an invoice with Fortnox Finans
     *
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceCreatePayloadWrap|null $payload Request body for create nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoCreate'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function noxInvoiceControllerDoCreate($payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoCreate'][0])
    {
        list($response) = $this->noxInvoiceControllerDoCreateWithHttpInfo($payload, $contentType);
        return $response;
    }

    /**
     * Operation noxInvoiceControllerDoCreateWithHttpInfo
     *
     * Send an invoice with Fortnox Finans
     *
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceCreatePayloadWrap|null $payload Request body for create nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoCreate'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function noxInvoiceControllerDoCreateWithHttpInfo($payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoCreate'][0])
    {
        $request = $this->noxInvoiceControllerDoCreateRequest($payload, $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\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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\FortnoxKfNoxInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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 noxInvoiceControllerDoCreateAsync
     *
     * Send an invoice with Fortnox Finans
     *
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceCreatePayloadWrap|null $payload Request body for create nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoCreateAsync($payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoCreate'][0])
    {
        return $this->noxInvoiceControllerDoCreateAsyncWithHttpInfo($payload, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation noxInvoiceControllerDoCreateAsyncWithHttpInfo
     *
     * Send an invoice with Fortnox Finans
     *
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceCreatePayloadWrap|null $payload Request body for create nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoCreateAsyncWithHttpInfo($payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoCreate'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap';
        $request = $this->noxInvoiceControllerDoCreateRequest($payload, $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 'noxInvoiceControllerDoCreate'
     *
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceCreatePayloadWrap|null $payload Request body for create nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function noxInvoiceControllerDoCreateRequest($payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoCreate'][0])
    {



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





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

        // for model (json/xml)
        if (isset($payload)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($payload));
            } else {
                $httpBody = $payload;
            }
        } 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 noxInvoiceControllerDoShow
     *
     * Retrieve a single invoice payment
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoShow'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function noxInvoiceControllerDoShow($invoice_number, string $contentType = self::contentTypes['noxInvoiceControllerDoShow'][0])
    {
        list($response) = $this->noxInvoiceControllerDoShowWithHttpInfo($invoice_number, $contentType);
        return $response;
    }

    /**
     * Operation noxInvoiceControllerDoShowWithHttpInfo
     *
     * Retrieve a single invoice payment
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoShow'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function noxInvoiceControllerDoShowWithHttpInfo($invoice_number, string $contentType = self::contentTypes['noxInvoiceControllerDoShow'][0])
    {
        $request = $this->noxInvoiceControllerDoShowRequest($invoice_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\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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\FortnoxKfNoxInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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 noxInvoiceControllerDoShowAsync
     *
     * Retrieve a single invoice payment
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoShowAsync($invoice_number, string $contentType = self::contentTypes['noxInvoiceControllerDoShow'][0])
    {
        return $this->noxInvoiceControllerDoShowAsyncWithHttpInfo($invoice_number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

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


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



        // path params
        if ($invoice_number !== null) {
            $resourcePath = str_replace(
                '{' . 'InvoiceNumber' . '}',
                ObjectSerializer::toPathValue($invoice_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 noxInvoiceControllerDoUpdateAndPause
     *
     * Action Pause
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndPausePayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndPause'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function noxInvoiceControllerDoUpdateAndPause($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndPause'][0])
    {
        list($response) = $this->noxInvoiceControllerDoUpdateAndPauseWithHttpInfo($invoice_number, $payload, $contentType);
        return $response;
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndPauseWithHttpInfo
     *
     * Action Pause
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndPausePayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndPause'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function noxInvoiceControllerDoUpdateAndPauseWithHttpInfo($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndPause'][0])
    {
        $request = $this->noxInvoiceControllerDoUpdateAndPauseRequest($invoice_number, $payload, $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\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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\FortnoxKfNoxInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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 noxInvoiceControllerDoUpdateAndPauseAsync
     *
     * Action Pause
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndPausePayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndPause'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndPauseAsync($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndPause'][0])
    {
        return $this->noxInvoiceControllerDoUpdateAndPauseAsyncWithHttpInfo($invoice_number, $payload, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndPauseAsyncWithHttpInfo
     *
     * Action Pause
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndPausePayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndPause'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndPauseAsyncWithHttpInfo($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndPause'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap';
        $request = $this->noxInvoiceControllerDoUpdateAndPauseRequest($invoice_number, $payload, $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 'noxInvoiceControllerDoUpdateAndPause'
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndPausePayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndPause'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function noxInvoiceControllerDoUpdateAndPauseRequest($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndPause'][0])
    {

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



        $resourcePath = '/3/noxfinansinvoices/{InvoiceNumber}/pause';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($payload)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($payload));
            } else {
                $httpBody = $payload;
            }
        } 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 noxInvoiceControllerDoUpdateAndRepostPayment
     *
     * Action Report Payment
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndRepostPaymentPayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function noxInvoiceControllerDoUpdateAndRepostPayment($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'][0])
    {
        list($response) = $this->noxInvoiceControllerDoUpdateAndRepostPaymentWithHttpInfo($invoice_number, $payload, $contentType);
        return $response;
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndRepostPaymentWithHttpInfo
     *
     * Action Report Payment
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndRepostPaymentPayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function noxInvoiceControllerDoUpdateAndRepostPaymentWithHttpInfo($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'][0])
    {
        $request = $this->noxInvoiceControllerDoUpdateAndRepostPaymentRequest($invoice_number, $payload, $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\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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\FortnoxKfNoxInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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 noxInvoiceControllerDoUpdateAndRepostPaymentAsync
     *
     * Action Report Payment
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndRepostPaymentPayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndRepostPaymentAsync($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'][0])
    {
        return $this->noxInvoiceControllerDoUpdateAndRepostPaymentAsyncWithHttpInfo($invoice_number, $payload, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndRepostPaymentAsyncWithHttpInfo
     *
     * Action Report Payment
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndRepostPaymentPayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndRepostPaymentAsyncWithHttpInfo($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap';
        $request = $this->noxInvoiceControllerDoUpdateAndRepostPaymentRequest($invoice_number, $payload, $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 'noxInvoiceControllerDoUpdateAndRepostPayment'
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndRepostPaymentPayloadWrap|null $payload Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function noxInvoiceControllerDoUpdateAndRepostPaymentRequest($invoice_number, $payload = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndRepostPayment'][0])
    {

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



        $resourcePath = '/3/noxfinansinvoices/{InvoiceNumber}/report-payment';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($payload)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($payload));
            } else {
                $httpBody = $payload;
            }
        } 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 noxInvoiceControllerDoUpdateAndStop
     *
     * Action Stop
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndStopPayloadWrap|null $fortnox_kf_nox_invoice_update_and_stop_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndStop'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function noxInvoiceControllerDoUpdateAndStop($invoice_number, $fortnox_kf_nox_invoice_update_and_stop_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndStop'][0])
    {
        list($response) = $this->noxInvoiceControllerDoUpdateAndStopWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_stop_payload_wrap, $contentType);
        return $response;
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndStopWithHttpInfo
     *
     * Action Stop
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndStopPayloadWrap|null $fortnox_kf_nox_invoice_update_and_stop_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndStop'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function noxInvoiceControllerDoUpdateAndStopWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_stop_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndStop'][0])
    {
        $request = $this->noxInvoiceControllerDoUpdateAndStopRequest($invoice_number, $fortnox_kf_nox_invoice_update_and_stop_payload_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\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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\FortnoxKfNoxInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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 noxInvoiceControllerDoUpdateAndStopAsync
     *
     * Action Stop
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndStopPayloadWrap|null $fortnox_kf_nox_invoice_update_and_stop_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndStop'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndStopAsync($invoice_number, $fortnox_kf_nox_invoice_update_and_stop_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndStop'][0])
    {
        return $this->noxInvoiceControllerDoUpdateAndStopAsyncWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_stop_payload_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndStopAsyncWithHttpInfo
     *
     * Action Stop
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndStopPayloadWrap|null $fortnox_kf_nox_invoice_update_and_stop_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndStop'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndStopAsyncWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_stop_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndStop'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap';
        $request = $this->noxInvoiceControllerDoUpdateAndStopRequest($invoice_number, $fortnox_kf_nox_invoice_update_and_stop_payload_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 'noxInvoiceControllerDoUpdateAndStop'
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndStopPayloadWrap|null $fortnox_kf_nox_invoice_update_and_stop_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndStop'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function noxInvoiceControllerDoUpdateAndStopRequest($invoice_number, $fortnox_kf_nox_invoice_update_and_stop_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndStop'][0])
    {

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



        $resourcePath = '/3/noxfinansinvoices/{InvoiceNumber}/stop';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($fortnox_kf_nox_invoice_update_and_stop_payload_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_kf_nox_invoice_update_and_stop_payload_wrap));
            } else {
                $httpBody = $fortnox_kf_nox_invoice_update_and_stop_payload_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 noxInvoiceControllerDoUpdateAndTakeFees
     *
     * Action Take Fees
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndTakeFeesPayloadWrap|null $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function noxInvoiceControllerDoUpdateAndTakeFees($invoice_number, $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'][0])
    {
        list($response) = $this->noxInvoiceControllerDoUpdateAndTakeFeesWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap, $contentType);
        return $response;
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndTakeFeesWithHttpInfo
     *
     * Action Take Fees
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndTakeFeesPayloadWrap|null $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function noxInvoiceControllerDoUpdateAndTakeFeesWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'][0])
    {
        $request = $this->noxInvoiceControllerDoUpdateAndTakeFeesRequest($invoice_number, $fortnox_kf_nox_invoice_update_and_take_fees_payload_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\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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\FortnoxKfNoxInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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 noxInvoiceControllerDoUpdateAndTakeFeesAsync
     *
     * Action Take Fees
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndTakeFeesPayloadWrap|null $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndTakeFeesAsync($invoice_number, $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'][0])
    {
        return $this->noxInvoiceControllerDoUpdateAndTakeFeesAsyncWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndTakeFeesAsyncWithHttpInfo
     *
     * Action Take Fees
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndTakeFeesPayloadWrap|null $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndTakeFeesAsyncWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap';
        $request = $this->noxInvoiceControllerDoUpdateAndTakeFeesRequest($invoice_number, $fortnox_kf_nox_invoice_update_and_take_fees_payload_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 'noxInvoiceControllerDoUpdateAndTakeFees'
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndTakeFeesPayloadWrap|null $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function noxInvoiceControllerDoUpdateAndTakeFeesRequest($invoice_number, $fortnox_kf_nox_invoice_update_and_take_fees_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndTakeFees'][0])
    {

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



        $resourcePath = '/3/noxfinansinvoices/{InvoiceNumber}/take-fees';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($fortnox_kf_nox_invoice_update_and_take_fees_payload_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_kf_nox_invoice_update_and_take_fees_payload_wrap));
            } else {
                $httpBody = $fortnox_kf_nox_invoice_update_and_take_fees_payload_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 noxInvoiceControllerDoUpdateAndUnpause
     *
     * Action Unpause
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndUnpausePayloadWrap|null $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function noxInvoiceControllerDoUpdateAndUnpause($invoice_number, $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'][0])
    {
        list($response) = $this->noxInvoiceControllerDoUpdateAndUnpauseWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap, $contentType);
        return $response;
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndUnpauseWithHttpInfo
     *
     * Action Unpause
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndUnpausePayloadWrap|null $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'] 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\FortnoxKfNoxInvoiceSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function noxInvoiceControllerDoUpdateAndUnpauseWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'][0])
    {
        $request = $this->noxInvoiceControllerDoUpdateAndUnpauseRequest($invoice_number, $fortnox_kf_nox_invoice_update_and_unpause_payload_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\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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\FortnoxKfNoxInvoiceSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap',
                        $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 noxInvoiceControllerDoUpdateAndUnpauseAsync
     *
     * Action Unpause
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndUnpausePayloadWrap|null $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndUnpauseAsync($invoice_number, $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'][0])
    {
        return $this->noxInvoiceControllerDoUpdateAndUnpauseAsyncWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation noxInvoiceControllerDoUpdateAndUnpauseAsyncWithHttpInfo
     *
     * Action Unpause
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndUnpausePayloadWrap|null $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function noxInvoiceControllerDoUpdateAndUnpauseAsyncWithHttpInfo($invoice_number, $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxKfNoxInvoiceSingleItemWrap';
        $request = $this->noxInvoiceControllerDoUpdateAndUnpauseRequest($invoice_number, $fortnox_kf_nox_invoice_update_and_unpause_payload_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 'noxInvoiceControllerDoUpdateAndUnpause'
     *
     * @param  string $invoice_number The Fortnox invoice number (required)
     * @param  \Fortnox\Model\FortnoxKfNoxInvoiceUpdateAndUnpausePayloadWrap|null $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap Request body for update nox finans invoice (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function noxInvoiceControllerDoUpdateAndUnpauseRequest($invoice_number, $fortnox_kf_nox_invoice_update_and_unpause_payload_wrap = null, string $contentType = self::contentTypes['noxInvoiceControllerDoUpdateAndUnpause'][0])
    {

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



        $resourcePath = '/3/noxfinansinvoices/{InvoiceNumber}/unpause';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($fortnox_kf_nox_invoice_update_and_unpause_payload_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_kf_nox_invoice_update_and_unpause_payload_wrap));
            } else {
                $httpBody = $fortnox_kf_nox_invoice_update_and_unpause_payload_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;
    }
}
