<?php
/**
 * SearchAPIApi
 * PHP version 7.4
 *
 * @category Class
 * @package  OpenAPI\Client
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * Flotiq User API
 *
 * ## Getting started  This API Documentation reflects the endpoints defined in your [Flotiq](https://flotiq.com) account. The documentation is generated using an OpenAPI schema describing the API, which can be obtained in several flavors:  - [OAS 3.0/3.1](https://api.flotiq.com/api/v1/open-api-schema.json?auth_token=REPLACE_KEY_VALUE)   - without hydration, will not expand relations between content types (this is the default version which provides maximum compatibility with downstream systems)   - with hydration, pass [hydrate=1](https://api.flotiq.com/api/v1/open-api-schema.json?auth_token=REPLACE_KEY_VALUE&amp;hydrate=1) - use this for a better type support in exported OpenAPI schemas   - without system endpoints, pass [user_only=1](https://api.flotiq.com/api/v1/open-api-schema.json?auth_token=REPLACE_KEY_VALUE&amp;hydrate=1&amp;user_only=1) - use this to only include your endpoints, without system ones   - for version 3.1, pass [version=3.1](https://api.flotiq.com/api/v1/open-api-schema.json?auth_token=REPLACE_KEY_VALUE&amp;version=3.1) - [OAS 2.0](https://api.flotiq.com/api/v1/open-api-schema.json?auth_token=REPLACE_KEY_VALUE&amp;version=2) - provided for compatibility with several older systems  Check Flotiq documentation for more information about [Flotiq OpenAPI capabilities](https://flotiq.com/docs/API/open-api-schema/), instructions how to generate code and other useful tips.  ### Access to data  There are several methods that you can use to access your data:  * Live API docs - available via &lt;code&gt;Try it out&lt;/code&gt; button available next to each endpoint   * Copying example code on the right side of each endpoint  * By downloading the SDKs available in multiple languages.  * By downloading the Postman collection and importing it into Postman.    Each of these methods is described in length in the [user documentation](https://flotiq.com/docs/).   ### Authorization   In order to make use of the provided documentation, example code, SDKs and so on - you will need to pull out your API key. We recommend that you start with the ReadOnly API Key which will allow you to make all the `GET` requests but will error-out when you try to modify content. Please remember to replace the key for `POST`, `PUT` and `DELETE` calls.   It&#039;s also possible to use scoped API keys - you can create those in the API keys section of the Flotiq user interface. This will allow you to create a key that only authorizes access to a specific content type (or a set of content types, if you choose so). Read more about how to use and create API keys in the [API keys documentation](https://flotiq.com/docs/API/).   ## Object access   Once you define a Content Type it will become available in your Content API as a set of endpoints that will allow you to work with objects:   * create  * list  * update  * delete  * batch create  * retrieve single object.  ### Hydration   When you build Content Types that have relation to others your objects will optionally support hydration of related entities. The endpoints that support object retrieval accept a `hydrate` parameter, which can be used to easily fetch hydrated objects. Since this breaks the standard REST concepts - it&#039;s not enabled by default, but it&#039;s a very handy feature that allows to reduce the amount of HTTP requests sent over the wire and we strongly recommend to use it.
 *
 * The version of the OpenAPI document: 2.0.1
 * Contact: hello@flotiq.com
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 6.0.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 OpenAPI\Client\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 OpenAPI\Client\ApiException;
use OpenAPI\Client\Configuration;
use OpenAPI\Client\HeaderSelector;
use OpenAPI\Client\ObjectSerializer;

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

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

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

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

    /**
     * @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,
        $hostIndex = 0
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: new Configuration();
        $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 search
     *
     * @param  string $q Query (optional, default to '')
     * @param  string[] $fields Search only in selected fields. (optional)
     * @param  string $page Listing page number, 1-based (optional, default to '1')
     * @param  string $limit Page limit (optional, default to '20')
     * @param  string $order_by Order by field (optional, default to '')
     * @param  string $order_direction Order direction (optional, default to 'asc')
     * @param  string[] $content_type Restrict search to content types set (optional)
     * @param  string[] $aggregate_by Field to aggregate results direction (string fields only) (optional)
     * @param  string[] $aggregate_by_numeric Field to aggregate results direction with numeric type (optional)
     * @param  object $filters Filter by object properties. Expected format: filters[property1]&#x3D;value1&amp;filters[property2]&#x3D;value2 (optional)
     * @param  object $post_filters Filter by object properties. Use it when you want aggregated counts without filters applied. Expected format: post_filters[property1]&#x3D;value1&amp;post_filters[property2]&#x3D;value2 (optional)
     * @param  object $geo_filters Filter by object geolocation properties. Example value: geo_filters[location]&#x3D;geo_distance,1.50km,40.1,-19.2 (filter name, distance, latitude, longitude). For more information see ElasticSearch docs. Only geo_distance query is supported. (optional)
     * @param  float $hydrate Hydrate level for relations to get a schema properly reflecting linked objects (optional)
     *
     * @throws \OpenAPI\Client\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \OpenAPI\Client\Model\SearchResponse|\OpenAPI\Client\Model\Search400Response|\OpenAPI\Client\Model\Model401Response
     */
    public function search($q = '', $fields = null, $page = '1', $limit = '20', $order_by = '', $order_direction = 'asc', $content_type = null, $aggregate_by = null, $aggregate_by_numeric = null, $filters = null, $post_filters = null, $geo_filters = null, $hydrate = null)
    {
        list($response) = $this->searchWithHttpInfo($q, $fields, $page, $limit, $order_by, $order_direction, $content_type, $aggregate_by, $aggregate_by_numeric, $filters, $post_filters, $geo_filters, $hydrate);
        return $response;
    }

    /**
     * Operation searchWithHttpInfo
     *
     * @param  string $q Query (optional, default to '')
     * @param  string[] $fields Search only in selected fields. (optional)
     * @param  string $page Listing page number, 1-based (optional, default to '1')
     * @param  string $limit Page limit (optional, default to '20')
     * @param  string $order_by Order by field (optional, default to '')
     * @param  string $order_direction Order direction (optional, default to 'asc')
     * @param  string[] $content_type Restrict search to content types set (optional)
     * @param  string[] $aggregate_by Field to aggregate results direction (string fields only) (optional)
     * @param  string[] $aggregate_by_numeric Field to aggregate results direction with numeric type (optional)
     * @param  object $filters Filter by object properties. Expected format: filters[property1]&#x3D;value1&amp;filters[property2]&#x3D;value2 (optional)
     * @param  object $post_filters Filter by object properties. Use it when you want aggregated counts without filters applied. Expected format: post_filters[property1]&#x3D;value1&amp;post_filters[property2]&#x3D;value2 (optional)
     * @param  object $geo_filters Filter by object geolocation properties. Example value: geo_filters[location]&#x3D;geo_distance,1.50km,40.1,-19.2 (filter name, distance, latitude, longitude). For more information see ElasticSearch docs. Only geo_distance query is supported. (optional)
     * @param  float $hydrate Hydrate level for relations to get a schema properly reflecting linked objects (optional)
     *
     * @throws \OpenAPI\Client\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \OpenAPI\Client\Model\SearchResponse|\OpenAPI\Client\Model\Search400Response|\OpenAPI\Client\Model\Model401Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function searchWithHttpInfo($q = '', $fields = null, $page = '1', $limit = '20', $order_by = '', $order_direction = 'asc', $content_type = null, $aggregate_by = null, $aggregate_by_numeric = null, $filters = null, $post_filters = null, $geo_filters = null, $hydrate = null)
    {
        $request = $this->searchRequest($q, $fields, $page, $limit, $order_by, $order_direction, $content_type, $aggregate_by, $aggregate_by_numeric, $filters, $post_filters, $geo_filters, $hydrate);

        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();

            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()
                );
            }

            switch($statusCode) {
                case 200:
                    if ('\OpenAPI\Client\Model\SearchResponse' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\OpenAPI\Client\Model\SearchResponse' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\SearchResponse', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\OpenAPI\Client\Model\Search400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\OpenAPI\Client\Model\Search400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Search400Response', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\OpenAPI\Client\Model\Model401Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\OpenAPI\Client\Model\Model401Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\Model401Response', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = '\OpenAPI\Client\Model\SearchResponse';
            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()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\OpenAPI\Client\Model\SearchResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\OpenAPI\Client\Model\Search400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\OpenAPI\Client\Model\Model401Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation searchAsync
     *
     * @param  string $q Query (optional, default to '')
     * @param  string[] $fields Search only in selected fields. (optional)
     * @param  string $page Listing page number, 1-based (optional, default to '1')
     * @param  string $limit Page limit (optional, default to '20')
     * @param  string $order_by Order by field (optional, default to '')
     * @param  string $order_direction Order direction (optional, default to 'asc')
     * @param  string[] $content_type Restrict search to content types set (optional)
     * @param  string[] $aggregate_by Field to aggregate results direction (string fields only) (optional)
     * @param  string[] $aggregate_by_numeric Field to aggregate results direction with numeric type (optional)
     * @param  object $filters Filter by object properties. Expected format: filters[property1]&#x3D;value1&amp;filters[property2]&#x3D;value2 (optional)
     * @param  object $post_filters Filter by object properties. Use it when you want aggregated counts without filters applied. Expected format: post_filters[property1]&#x3D;value1&amp;post_filters[property2]&#x3D;value2 (optional)
     * @param  object $geo_filters Filter by object geolocation properties. Example value: geo_filters[location]&#x3D;geo_distance,1.50km,40.1,-19.2 (filter name, distance, latitude, longitude). For more information see ElasticSearch docs. Only geo_distance query is supported. (optional)
     * @param  float $hydrate Hydrate level for relations to get a schema properly reflecting linked objects (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function searchAsync($q = '', $fields = null, $page = '1', $limit = '20', $order_by = '', $order_direction = 'asc', $content_type = null, $aggregate_by = null, $aggregate_by_numeric = null, $filters = null, $post_filters = null, $geo_filters = null, $hydrate = null)
    {
        return $this->searchAsyncWithHttpInfo($q, $fields, $page, $limit, $order_by, $order_direction, $content_type, $aggregate_by, $aggregate_by_numeric, $filters, $post_filters, $geo_filters, $hydrate)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation searchAsyncWithHttpInfo
     *
     * @param  string $q Query (optional, default to '')
     * @param  string[] $fields Search only in selected fields. (optional)
     * @param  string $page Listing page number, 1-based (optional, default to '1')
     * @param  string $limit Page limit (optional, default to '20')
     * @param  string $order_by Order by field (optional, default to '')
     * @param  string $order_direction Order direction (optional, default to 'asc')
     * @param  string[] $content_type Restrict search to content types set (optional)
     * @param  string[] $aggregate_by Field to aggregate results direction (string fields only) (optional)
     * @param  string[] $aggregate_by_numeric Field to aggregate results direction with numeric type (optional)
     * @param  object $filters Filter by object properties. Expected format: filters[property1]&#x3D;value1&amp;filters[property2]&#x3D;value2 (optional)
     * @param  object $post_filters Filter by object properties. Use it when you want aggregated counts without filters applied. Expected format: post_filters[property1]&#x3D;value1&amp;post_filters[property2]&#x3D;value2 (optional)
     * @param  object $geo_filters Filter by object geolocation properties. Example value: geo_filters[location]&#x3D;geo_distance,1.50km,40.1,-19.2 (filter name, distance, latitude, longitude). For more information see ElasticSearch docs. Only geo_distance query is supported. (optional)
     * @param  float $hydrate Hydrate level for relations to get a schema properly reflecting linked objects (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function searchAsyncWithHttpInfo($q = '', $fields = null, $page = '1', $limit = '20', $order_by = '', $order_direction = 'asc', $content_type = null, $aggregate_by = null, $aggregate_by_numeric = null, $filters = null, $post_filters = null, $geo_filters = null, $hydrate = null)
    {
        $returnType = '\OpenAPI\Client\Model\SearchResponse';
        $request = $this->searchRequest($q, $fields, $page, $limit, $order_by, $order_direction, $content_type, $aggregate_by, $aggregate_by_numeric, $filters, $post_filters, $geo_filters, $hydrate);

        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 'search'
     *
     * @param  string $q Query (optional, default to '')
     * @param  string[] $fields Search only in selected fields. (optional)
     * @param  string $page Listing page number, 1-based (optional, default to '1')
     * @param  string $limit Page limit (optional, default to '20')
     * @param  string $order_by Order by field (optional, default to '')
     * @param  string $order_direction Order direction (optional, default to 'asc')
     * @param  string[] $content_type Restrict search to content types set (optional)
     * @param  string[] $aggregate_by Field to aggregate results direction (string fields only) (optional)
     * @param  string[] $aggregate_by_numeric Field to aggregate results direction with numeric type (optional)
     * @param  object $filters Filter by object properties. Expected format: filters[property1]&#x3D;value1&amp;filters[property2]&#x3D;value2 (optional)
     * @param  object $post_filters Filter by object properties. Use it when you want aggregated counts without filters applied. Expected format: post_filters[property1]&#x3D;value1&amp;post_filters[property2]&#x3D;value2 (optional)
     * @param  object $geo_filters Filter by object geolocation properties. Example value: geo_filters[location]&#x3D;geo_distance,1.50km,40.1,-19.2 (filter name, distance, latitude, longitude). For more information see ElasticSearch docs. Only geo_distance query is supported. (optional)
     * @param  float $hydrate Hydrate level for relations to get a schema properly reflecting linked objects (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function searchRequest($q = '', $fields = null, $page = '1', $limit = '20', $order_by = '', $order_direction = 'asc', $content_type = null, $aggregate_by = null, $aggregate_by_numeric = null, $filters = null, $post_filters = null, $geo_filters = null, $hydrate = null)
    {
        if ($hydrate !== null && $hydrate > 2) {
            throw new \InvalidArgumentException('invalid value for "$hydrate" when calling SearchAPIApi.search, must be smaller than or equal to 2.');
        }


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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $q,
            'q', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields,
            'fields[]', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page,
            'page', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $limit,
            'limit', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $order_by,
            'order_by', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $order_direction,
            'order_direction', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $content_type,
            'content_type[]', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $aggregate_by,
            'aggregate_by[]', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $aggregate_by_numeric,
            'aggregate_by_numeric[]', // param base name
            'array', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $filters,
            'filters', // param base name
            'object', // openApiType
            'deepObject', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $post_filters,
            'post_filters', // param base name
            'object', // openApiType
            'deepObject', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $geo_filters,
            'geo_filters', // param base name
            'object', // openApiType
            'deepObject', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $hydrate,
            'hydrate', // param base name
            'number', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);




        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // 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 ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('X-AUTH-TOKEN');
        if ($apiKey !== null) {
            $headers['X-AUTH-TOKEN'] = $apiKey;
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $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());
            }
        }

        return $options;
    }
}
