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

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

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

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

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

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'customerControllerDoCreate' => [
            'application/json',
        ],
        'customerControllerDoDelete' => [
            'application/json',
        ],
        'customerControllerDoIndex' => [
            'application/json',
        ],
        'customerControllerDoShow' => [
            'application/json',
        ],
        'customerControllerDoUpdate' => [
            '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 customerControllerDoCreate
     *
     * Create a customer
     *
     * @param  \Fortnox\Model\FortnoxKfCustomerSinglePayloadItemWrap|null $customer Request body for create customer (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoCreate'] 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\FortnoxKfCustomerSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function customerControllerDoCreate($customer = null, string $contentType = self::contentTypes['customerControllerDoCreate'][0])
    {
        list($response) = $this->customerControllerDoCreateWithHttpInfo($customer, $contentType);
        return $response;
    }

    /**
     * Operation customerControllerDoCreateWithHttpInfo
     *
     * Create a customer
     *
     * @param  \Fortnox\Model\FortnoxKfCustomerSinglePayloadItemWrap|null $customer Request body for create customer (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoCreate'] 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\FortnoxKfCustomerSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function customerControllerDoCreateWithHttpInfo($customer = null, string $contentType = self::contentTypes['customerControllerDoCreate'][0])
    {
        $request = $this->customerControllerDoCreateRequest($customer, $contentType);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 201:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxKfCustomerSingleItemWrap',
                        $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\FortnoxKfCustomerSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfCustomerSingleItemWrap',
                        $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 customerControllerDoCreateAsync
     *
     * Create a customer
     *
     * @param  \Fortnox\Model\FortnoxKfCustomerSinglePayloadItemWrap|null $customer Request body for create customer (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoCreate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function customerControllerDoCreateAsync($customer = null, string $contentType = self::contentTypes['customerControllerDoCreate'][0])
    {
        return $this->customerControllerDoCreateAsyncWithHttpInfo($customer, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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



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





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

        // for model (json/xml)
        if (isset($customer)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($customer));
            } else {
                $httpBody = $customer;
            }
        } 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 customerControllerDoDelete
     *
     * Delete a customer
     *
     * @param  string $customer_number Customer number of customer to delete (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoDelete'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return void
     */
    public function customerControllerDoDelete($customer_number, string $contentType = self::contentTypes['customerControllerDoDelete'][0])
    {
        $this->customerControllerDoDeleteWithHttpInfo($customer_number, $contentType);
    }

    /**
     * Operation customerControllerDoDeleteWithHttpInfo
     *
     * Delete a customer
     *
     * @param  string $customer_number Customer number of customer to delete (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoDelete'] to see the possible values for this operation
     *
     * @throws \Fortnox\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function customerControllerDoDeleteWithHttpInfo($customer_number, string $contentType = self::contentTypes['customerControllerDoDelete'][0])
    {
        $request = $this->customerControllerDoDeleteRequest($customer_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();


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

            throw $e;
        }
    }

    /**
     * Operation customerControllerDoDeleteAsync
     *
     * Delete a customer
     *
     * @param  string $customer_number Customer number of customer to delete (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoDelete'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function customerControllerDoDeleteAsync($customer_number, string $contentType = self::contentTypes['customerControllerDoDelete'][0])
    {
        return $this->customerControllerDoDeleteAsyncWithHttpInfo($customer_number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation customerControllerDoDeleteAsyncWithHttpInfo
     *
     * Delete a customer
     *
     * @param  string $customer_number Customer number of customer to delete (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoDelete'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function customerControllerDoDeleteAsyncWithHttpInfo($customer_number, string $contentType = self::contentTypes['customerControllerDoDelete'][0])
    {
        $returnType = '';
        $request = $this->customerControllerDoDeleteRequest($customer_number, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'customerControllerDoDelete'
     *
     * @param  string $customer_number Customer number of customer to delete (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoDelete'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function customerControllerDoDeleteRequest($customer_number, string $contentType = self::contentTypes['customerControllerDoDelete'][0])
    {

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


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



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

    /**
     * Operation customerControllerDoIndex
     *
     * Retrieve a list of customers
     *
     * @param  string|null $filter possibility to filter customers (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $name filter by name (optional)
     * @param  string|null $zipcode filter by zip code (optional)
     * @param  string|null $city filter by city (optional)
     * @param  string|null $email filter by email (optional)
     * @param  string|null $phone filter by phone (optional)
     * @param  string|null $organisationnumber filter by organisation number (optional)
     * @param  string|null $gln filter by gln (optional)
     * @param  string|null $glndelivery filter by gln delivery (optional)
     * @param  string|null $lastmodified filter by last modified (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoIndex'] 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\FortnoxKfCustomerListItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function customerControllerDoIndex($filter = null, $sortby = null, $customernumber = null, $name = null, $zipcode = null, $city = null, $email = null, $phone = null, $organisationnumber = null, $gln = null, $glndelivery = null, $lastmodified = null, string $contentType = self::contentTypes['customerControllerDoIndex'][0])
    {
        list($response) = $this->customerControllerDoIndexWithHttpInfo($filter, $sortby, $customernumber, $name, $zipcode, $city, $email, $phone, $organisationnumber, $gln, $glndelivery, $lastmodified, $contentType);
        return $response;
    }

    /**
     * Operation customerControllerDoIndexWithHttpInfo
     *
     * Retrieve a list of customers
     *
     * @param  string|null $filter possibility to filter customers (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $name filter by name (optional)
     * @param  string|null $zipcode filter by zip code (optional)
     * @param  string|null $city filter by city (optional)
     * @param  string|null $email filter by email (optional)
     * @param  string|null $phone filter by phone (optional)
     * @param  string|null $organisationnumber filter by organisation number (optional)
     * @param  string|null $gln filter by gln (optional)
     * @param  string|null $glndelivery filter by gln delivery (optional)
     * @param  string|null $lastmodified filter by last modified (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoIndex'] 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\FortnoxKfCustomerListItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function customerControllerDoIndexWithHttpInfo($filter = null, $sortby = null, $customernumber = null, $name = null, $zipcode = null, $city = null, $email = null, $phone = null, $organisationnumber = null, $gln = null, $glndelivery = null, $lastmodified = null, string $contentType = self::contentTypes['customerControllerDoIndex'][0])
    {
        $request = $this->customerControllerDoIndexRequest($filter, $sortby, $customernumber, $name, $zipcode, $city, $email, $phone, $organisationnumber, $gln, $glndelivery, $lastmodified, $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\FortnoxKfCustomerListItemWrap',
                        $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\FortnoxKfCustomerListItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfCustomerListItemWrap',
                        $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 customerControllerDoIndexAsync
     *
     * Retrieve a list of customers
     *
     * @param  string|null $filter possibility to filter customers (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $name filter by name (optional)
     * @param  string|null $zipcode filter by zip code (optional)
     * @param  string|null $city filter by city (optional)
     * @param  string|null $email filter by email (optional)
     * @param  string|null $phone filter by phone (optional)
     * @param  string|null $organisationnumber filter by organisation number (optional)
     * @param  string|null $gln filter by gln (optional)
     * @param  string|null $glndelivery filter by gln delivery (optional)
     * @param  string|null $lastmodified filter by last modified (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function customerControllerDoIndexAsync($filter = null, $sortby = null, $customernumber = null, $name = null, $zipcode = null, $city = null, $email = null, $phone = null, $organisationnumber = null, $gln = null, $glndelivery = null, $lastmodified = null, string $contentType = self::contentTypes['customerControllerDoIndex'][0])
    {
        return $this->customerControllerDoIndexAsyncWithHttpInfo($filter, $sortby, $customernumber, $name, $zipcode, $city, $email, $phone, $organisationnumber, $gln, $glndelivery, $lastmodified, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation customerControllerDoIndexAsyncWithHttpInfo
     *
     * Retrieve a list of customers
     *
     * @param  string|null $filter possibility to filter customers (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $name filter by name (optional)
     * @param  string|null $zipcode filter by zip code (optional)
     * @param  string|null $city filter by city (optional)
     * @param  string|null $email filter by email (optional)
     * @param  string|null $phone filter by phone (optional)
     * @param  string|null $organisationnumber filter by organisation number (optional)
     * @param  string|null $gln filter by gln (optional)
     * @param  string|null $glndelivery filter by gln delivery (optional)
     * @param  string|null $lastmodified filter by last modified (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function customerControllerDoIndexAsyncWithHttpInfo($filter = null, $sortby = null, $customernumber = null, $name = null, $zipcode = null, $city = null, $email = null, $phone = null, $organisationnumber = null, $gln = null, $glndelivery = null, $lastmodified = null, string $contentType = self::contentTypes['customerControllerDoIndex'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxKfCustomerListItemWrap';
        $request = $this->customerControllerDoIndexRequest($filter, $sortby, $customernumber, $name, $zipcode, $city, $email, $phone, $organisationnumber, $gln, $glndelivery, $lastmodified, $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 'customerControllerDoIndex'
     *
     * @param  string|null $filter possibility to filter customers (optional)
     * @param  string|null $sortby field to sort returned list (optional)
     * @param  string|null $customernumber filter by customer number (optional)
     * @param  string|null $name filter by name (optional)
     * @param  string|null $zipcode filter by zip code (optional)
     * @param  string|null $city filter by city (optional)
     * @param  string|null $email filter by email (optional)
     * @param  string|null $phone filter by phone (optional)
     * @param  string|null $organisationnumber filter by organisation number (optional)
     * @param  string|null $gln filter by gln (optional)
     * @param  string|null $glndelivery filter by gln delivery (optional)
     * @param  string|null $lastmodified filter by last modified (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoIndex'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function customerControllerDoIndexRequest($filter = null, $sortby = null, $customernumber = null, $name = null, $zipcode = null, $city = null, $email = null, $phone = null, $organisationnumber = null, $gln = null, $glndelivery = null, $lastmodified = null, string $contentType = self::contentTypes['customerControllerDoIndex'][0])
    {














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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $filter,
            'filter', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $sortby,
            'sortby', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $customernumber,
            'customernumber', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $name,
            'name', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $zipcode,
            'zipcode', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $city,
            'city', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $email,
            'email', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $phone,
            'phone', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $organisationnumber,
            'organisationnumber', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $gln,
            'gln', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $glndelivery,
            'glndelivery', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $lastmodified,
            'lastmodified', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);




        $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 customerControllerDoShow
     *
     * Retrieve a customer
     *
     * @param  string $customer_number Customer number of customer to show (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoShow'] 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\FortnoxKfCustomerSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function customerControllerDoShow($customer_number, string $contentType = self::contentTypes['customerControllerDoShow'][0])
    {
        list($response) = $this->customerControllerDoShowWithHttpInfo($customer_number, $contentType);
        return $response;
    }

    /**
     * Operation customerControllerDoShowWithHttpInfo
     *
     * Retrieve a customer
     *
     * @param  string $customer_number Customer number of customer to show (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoShow'] 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\FortnoxKfCustomerSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function customerControllerDoShowWithHttpInfo($customer_number, string $contentType = self::contentTypes['customerControllerDoShow'][0])
    {
        $request = $this->customerControllerDoShowRequest($customer_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\FortnoxKfCustomerSingleItemWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxKfCustomerSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfCustomerSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation customerControllerDoShowAsync
     *
     * Retrieve a customer
     *
     * @param  string $customer_number Customer number of customer to show (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function customerControllerDoShowAsync($customer_number, string $contentType = self::contentTypes['customerControllerDoShow'][0])
    {
        return $this->customerControllerDoShowAsyncWithHttpInfo($customer_number, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation customerControllerDoShowAsyncWithHttpInfo
     *
     * Retrieve a customer
     *
     * @param  string $customer_number Customer number of customer to show (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function customerControllerDoShowAsyncWithHttpInfo($customer_number, string $contentType = self::contentTypes['customerControllerDoShow'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxKfCustomerSingleItemWrap';
        $request = $this->customerControllerDoShowRequest($customer_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 'customerControllerDoShow'
     *
     * @param  string $customer_number Customer number of customer to show (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoShow'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function customerControllerDoShowRequest($customer_number, string $contentType = self::contentTypes['customerControllerDoShow'][0])
    {

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


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



        // path params
        if ($customer_number !== null) {
            $resourcePath = str_replace(
                '{' . 'CustomerNumber' . '}',
                ObjectSerializer::toPathValue($customer_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 customerControllerDoUpdate
     *
     * Update a customer
     *
     * @param  string $customer_number Customer number of customer to update (required)
     * @param  \Fortnox\Model\FortnoxKfCustomerSinglePayloadItemWrap|null $customer Request body for update customer (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoUpdate'] 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\FortnoxKfCustomerSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap
     */
    public function customerControllerDoUpdate($customer_number, $customer = null, string $contentType = self::contentTypes['customerControllerDoUpdate'][0])
    {
        list($response) = $this->customerControllerDoUpdateWithHttpInfo($customer_number, $customer, $contentType);
        return $response;
    }

    /**
     * Operation customerControllerDoUpdateWithHttpInfo
     *
     * Update a customer
     *
     * @param  string $customer_number Customer number of customer to update (required)
     * @param  \Fortnox\Model\FortnoxKfCustomerSinglePayloadItemWrap|null $customer Request body for update customer (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoUpdate'] 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\FortnoxKfCustomerSingleItemWrap|\Fortnox\Model\FortnoxErrorInformationWrap|\Fortnox\Model\FortnoxErrorInformationWrap, HTTP status code, HTTP response headers (array of strings)
     */
    public function customerControllerDoUpdateWithHttpInfo($customer_number, $customer = null, string $contentType = self::contentTypes['customerControllerDoUpdate'][0])
    {
        $request = $this->customerControllerDoUpdateRequest($customer_number, $customer, $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\FortnoxKfCustomerSingleItemWrap',
                        $request,
                        $response,
                    );
                case 404:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
                default:
                    return $this->handleResponseWithDataType(
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $request,
                        $response,
                    );
            }

            

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Fortnox\Model\FortnoxKfCustomerSingleItemWrap',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxKfCustomerSingleItemWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                default:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Fortnox\Model\FortnoxErrorInformationWrap',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation customerControllerDoUpdateAsync
     *
     * Update a customer
     *
     * @param  string $customer_number Customer number of customer to update (required)
     * @param  \Fortnox\Model\FortnoxKfCustomerSinglePayloadItemWrap|null $customer Request body for update customer (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function customerControllerDoUpdateAsync($customer_number, $customer = null, string $contentType = self::contentTypes['customerControllerDoUpdate'][0])
    {
        return $this->customerControllerDoUpdateAsyncWithHttpInfo($customer_number, $customer, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation customerControllerDoUpdateAsyncWithHttpInfo
     *
     * Update a customer
     *
     * @param  string $customer_number Customer number of customer to update (required)
     * @param  \Fortnox\Model\FortnoxKfCustomerSinglePayloadItemWrap|null $customer Request body for update customer (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function customerControllerDoUpdateAsyncWithHttpInfo($customer_number, $customer = null, string $contentType = self::contentTypes['customerControllerDoUpdate'][0])
    {
        $returnType = '\Fortnox\Model\FortnoxKfCustomerSingleItemWrap';
        $request = $this->customerControllerDoUpdateRequest($customer_number, $customer, $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 'customerControllerDoUpdate'
     *
     * @param  string $customer_number Customer number of customer to update (required)
     * @param  \Fortnox\Model\FortnoxKfCustomerSinglePayloadItemWrap|null $customer Request body for update customer (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['customerControllerDoUpdate'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function customerControllerDoUpdateRequest($customer_number, $customer = null, string $contentType = self::contentTypes['customerControllerDoUpdate'][0])
    {

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



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



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


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

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