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

/**
 * Klaviyo API
 *
 * The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
 *
 * Contact: developers@klaviyo.com
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 6.1.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 KlaviyoAPI\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 KlaviyoAPI\ApiException;
use KlaviyoAPI\Configuration;
use KlaviyoAPI\HeaderSelector;
use KlaviyoAPI\ObjectSerializer;

/**
 * CouponsApi Class Doc Comment
 *
 * @category Class
 * @package  KlaviyoAPI
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */
class CouponsApi
{
    /**
     * @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 bulkCreateCouponCodes
     *
     * Bulk Create Coupon Codes
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateJobCreateQuery $coupon_code_create_job_create_query coupon_code_create_job_create_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function bulkCreateCouponCodes($coupon_code_create_job_create_query, $apiKey = null)
    {
        list($response) = $this->bulkCreateCouponCodesWithHttpInfo($coupon_code_create_job_create_query, $apiKey);
        return $response;
    }

    /**
     * Alias of `bulkCreateCouponCodes`
     *
     * @deprecated use `bulkCreateCouponCodes` instead
     */
    public function spawnCouponCodeBulkCreateJob(...$args) {
        return $this->bulkCreateCouponCodes(...$args);
    }

    /**
     * Alias of `bulkCreateCouponCodes`
     *
     * @deprecated use `bulkCreateCouponCodes` instead
     */
    public function createCouponCodeBulkCreateJob(...$args) {
        return $this->bulkCreateCouponCodes(...$args);
    }

    /**
     * Operation bulkCreateCouponCodesWithHttpInfo
     *
     * Bulk Create Coupon Codes
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateJobCreateQuery $coupon_code_create_job_create_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function bulkCreateCouponCodesWithHttpInfo($coupon_code_create_job_create_query, $apiKey = null)
    {
        $request = $this->bulkCreateCouponCodesRequest($coupon_code_create_job_create_query, $apiKey);

        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 202:
                    if ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 202:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Alias of `bulkCreateCouponCodesWithHttpInfo`
     *
     * @deprecated use `bulkCreateCouponCodesWithHttpInfo` instead
     */
    public function spawnCouponCodeBulkCreateJobWithHttpInfo(...$args) {
        return $this->bulkCreateCouponCodesWithHttpInfo(...$args);
    }

    /**
     * Alias of `bulkCreateCouponCodesWithHttpInfo`
     *
     * @deprecated use `bulkCreateCouponCodesWithHttpInfo` instead
     */
    public function createCouponCodeBulkCreateJobWithHttpInfo(...$args) {
        return $this->bulkCreateCouponCodesWithHttpInfo(...$args);
    }

    /**
     * Operation bulkCreateCouponCodesAsync
     *
     * Bulk Create Coupon Codes
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateJobCreateQuery $coupon_code_create_job_create_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function bulkCreateCouponCodesAsync($coupon_code_create_job_create_query, $apiKey = null)
    {
        return $this->bulkCreateCouponCodesAsyncWithHttpInfo($coupon_code_create_job_create_query, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Alias of `bulkCreateCouponCodesAsync`
     *
     * @deprecated use `bulkCreateCouponCodesAsync` instead
     */
    public function spawnCouponCodeBulkCreateJobAsync(...$args) {
        return $this->bulkCreateCouponCodesAsync(...$args);
    }

    /**
     * Alias of `bulkCreateCouponCodesAsync`
     *
     * @deprecated use `bulkCreateCouponCodesAsync` instead
     */
    public function createCouponCodeBulkCreateJobAsync(...$args) {
        return $this->bulkCreateCouponCodesAsync(...$args);
    }

    /**
     * Operation bulkCreateCouponCodesAsyncWithHttpInfo
     *
     * Bulk Create Coupon Codes
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateJobCreateQuery $coupon_code_create_job_create_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function bulkCreateCouponCodesAsyncWithHttpInfo($coupon_code_create_job_create_query, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->bulkCreateCouponCodesRequest($coupon_code_create_job_create_query, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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()
                    );
                }
            );
    }

    /**
     * Alias of `bulkCreateCouponCodesAsyncWithHttpInfo`
     *
     * @deprecated use `bulkCreateCouponCodesAsyncWithHttpInfo` instead
     */
    public function spawnCouponCodeBulkCreateJobAsyncWithHttpInfo(...$args) {
        return $this->bulkCreateCouponCodesAsyncWithHttpInfo(...$args);
    }

    /**
     * Alias of `bulkCreateCouponCodesAsyncWithHttpInfo`
     *
     * @deprecated use `bulkCreateCouponCodesAsyncWithHttpInfo` instead
     */
    public function createCouponCodeBulkCreateJobAsyncWithHttpInfo(...$args) {
        return $this->bulkCreateCouponCodesAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'bulkCreateCouponCodes'
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateJobCreateQuery $coupon_code_create_job_create_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function bulkCreateCouponCodesRequest($coupon_code_create_job_create_query, $apiKey = null)
    {
        // verify the required parameter 'coupon_code_create_job_create_query' is set
        if ($coupon_code_create_job_create_query === null || (is_array($coupon_code_create_job_create_query) && count($coupon_code_create_job_create_query) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $coupon_code_create_job_create_query when calling bulkCreateCouponCodes'
            );
        }

        $resourcePath = '/api/coupon-code-bulk-create-jobs';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;





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

        // for model (json/xml)
        if (isset($coupon_code_create_job_create_query)) {
            if ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($coupon_code_create_job_create_query));
            } else {
                $httpBody = $coupon_code_create_job_create_query;
            }
        } 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 ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Alias of `bulkCreateCouponCodesRequest`
     *
     * @deprecated use `bulkCreateCouponCodesRequest` instead
     */
    public function spawnCouponCodeBulkCreateJobRequest(...$args) {
        return $this->bulkCreateCouponCodesRequest(...$args);
    }

    /**
     * Alias of `bulkCreateCouponCodesRequest`
     *
     * @deprecated use `bulkCreateCouponCodesRequest` instead
     */
    public function createCouponCodeBulkCreateJobRequest(...$args) {
        return $this->bulkCreateCouponCodesRequest(...$args);
    }

    /**
     * Operation createCoupon
     *
     * Create Coupon
     *
     * @param  \KlaviyoAPI\Model\CouponCreateQuery $coupon_create_query coupon_create_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function createCoupon($coupon_create_query, $apiKey = null)
    {
        list($response) = $this->createCouponWithHttpInfo($coupon_create_query, $apiKey);
        return $response;
    }

    /**
     * Operation createCouponWithHttpInfo
     *
     * Create Coupon
     *
     * @param  \KlaviyoAPI\Model\CouponCreateQuery $coupon_create_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function createCouponWithHttpInfo($coupon_create_query, $apiKey = null)
    {
        $request = $this->createCouponRequest($coupon_create_query, $apiKey);

        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 201:
                    if ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 201:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation createCouponAsync
     *
     * Create Coupon
     *
     * @param  \KlaviyoAPI\Model\CouponCreateQuery $coupon_create_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCouponAsync($coupon_create_query, $apiKey = null)
    {
        return $this->createCouponAsyncWithHttpInfo($coupon_create_query, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation createCouponAsyncWithHttpInfo
     *
     * Create Coupon
     *
     * @param  \KlaviyoAPI\Model\CouponCreateQuery $coupon_create_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCouponAsyncWithHttpInfo($coupon_create_query, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->createCouponRequest($coupon_create_query, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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 'createCoupon'
     *
     * @param  \KlaviyoAPI\Model\CouponCreateQuery $coupon_create_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function createCouponRequest($coupon_create_query, $apiKey = null)
    {
        // verify the required parameter 'coupon_create_query' is set
        if ($coupon_create_query === null || (is_array($coupon_create_query) && count($coupon_create_query) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $coupon_create_query when calling createCoupon'
            );
        }

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





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

        // for model (json/xml)
        if (isset($coupon_create_query)) {
            if ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($coupon_create_query));
            } else {
                $httpBody = $coupon_create_query;
            }
        } 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 ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createCouponCode
     *
     * Create Coupon Code
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateQuery $coupon_code_create_query coupon_code_create_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function createCouponCode($coupon_code_create_query, $apiKey = null)
    {
        list($response) = $this->createCouponCodeWithHttpInfo($coupon_code_create_query, $apiKey);
        return $response;
    }

    /**
     * Operation createCouponCodeWithHttpInfo
     *
     * Create Coupon Code
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateQuery $coupon_code_create_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function createCouponCodeWithHttpInfo($coupon_code_create_query, $apiKey = null)
    {
        $request = $this->createCouponCodeRequest($coupon_code_create_query, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation createCouponCodeAsync
     *
     * Create Coupon Code
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateQuery $coupon_code_create_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCouponCodeAsync($coupon_code_create_query, $apiKey = null)
    {
        return $this->createCouponCodeAsyncWithHttpInfo($coupon_code_create_query, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation createCouponCodeAsyncWithHttpInfo
     *
     * Create Coupon Code
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateQuery $coupon_code_create_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCouponCodeAsyncWithHttpInfo($coupon_code_create_query, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->createCouponCodeRequest($coupon_code_create_query, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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 'createCouponCode'
     *
     * @param  \KlaviyoAPI\Model\CouponCodeCreateQuery $coupon_code_create_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function createCouponCodeRequest($coupon_code_create_query, $apiKey = null)
    {
        // verify the required parameter 'coupon_code_create_query' is set
        if ($coupon_code_create_query === null || (is_array($coupon_code_create_query) && count($coupon_code_create_query) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $coupon_code_create_query when calling createCouponCode'
            );
        }

        $resourcePath = '/api/coupon-codes';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;





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

        // for model (json/xml)
        if (isset($coupon_code_create_query)) {
            if ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($coupon_code_create_query));
            } else {
                $httpBody = $coupon_code_create_query;
            }
        } 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 ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation deleteCoupon
     *
     * Delete Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return void
     */
    public function deleteCoupon($id, $apiKey = null)
    {
        $this->deleteCouponWithHttpInfo($id, $apiKey);
    }

    /**
     * Operation deleteCouponWithHttpInfo
     *
     * Delete Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function deleteCouponWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->deleteCouponRequest($id, $apiKey);

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

            return [null, $statusCode, $response->getHeaders()];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation deleteCouponAsync
     *
     * Delete Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteCouponAsync($id, $apiKey = null)
    {
        return $this->deleteCouponAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteCouponAsyncWithHttpInfo
     *
     * Delete Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteCouponAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = '';
        $request = $this->deleteCouponRequest($id, $apiKey);

        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 'deleteCoupon'
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function deleteCouponRequest($id, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling deleteCoupon'
            );
        }

        $resourcePath = '/api/coupons/{id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'DELETE',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation deleteCouponCode
     *
     * Delete Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return void
     */
    public function deleteCouponCode($id, $apiKey = null)
    {
        $this->deleteCouponCodeWithHttpInfo($id, $apiKey);
    }

    /**
     * Operation deleteCouponCodeWithHttpInfo
     *
     * Delete Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function deleteCouponCodeWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->deleteCouponCodeRequest($id, $apiKey);

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

            return [null, $statusCode, $response->getHeaders()];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation deleteCouponCodeAsync
     *
     * Delete Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteCouponCodeAsync($id, $apiKey = null)
    {
        return $this->deleteCouponCodeAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteCouponCodeAsyncWithHttpInfo
     *
     * Delete Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteCouponCodeAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = '';
        $request = $this->deleteCouponCodeRequest($id, $apiKey);

        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 'deleteCouponCode'
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function deleteCouponCodeRequest($id, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling deleteCouponCode'
            );
        }

        $resourcePath = '/api/coupon-codes/{id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'DELETE',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getBulkCreateCouponCodeJobs
     *
     * Get Bulk Create Coupon Code Jobs
     *
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getBulkCreateCouponCodeJobs($fields_coupon_code_bulk_create_job = null, $filter = null, $page_cursor = null, $apiKey = null)
    {
        list($response) = $this->getBulkCreateCouponCodeJobsWithHttpInfo($fields_coupon_code_bulk_create_job, $filter, $page_cursor, $apiKey);
        return $response;
    }

    /**
     * Alias of `getBulkCreateCouponCodeJobs`
     *
     * @deprecated use `getBulkCreateCouponCodeJobs` instead
     */
    public function getCouponCodeBulkCreateJobs(...$args) {
        return $this->getBulkCreateCouponCodeJobs(...$args);
    }

    /**
     * Operation getBulkCreateCouponCodeJobsWithHttpInfo
     *
     * Get Bulk Create Coupon Code Jobs
     *
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getBulkCreateCouponCodeJobsWithHttpInfo($fields_coupon_code_bulk_create_job = null, $filter = null, $page_cursor = null, $apiKey = null)
    {
        $request = $this->getBulkCreateCouponCodeJobsRequest($fields_coupon_code_bulk_create_job, $filter, $page_cursor, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Alias of `getBulkCreateCouponCodeJobsWithHttpInfo`
     *
     * @deprecated use `getBulkCreateCouponCodeJobsWithHttpInfo` instead
     */
    public function getCouponCodeBulkCreateJobsWithHttpInfo(...$args) {
        return $this->getBulkCreateCouponCodeJobsWithHttpInfo(...$args);
    }

    /**
     * Operation getBulkCreateCouponCodeJobsAsync
     *
     * Get Bulk Create Coupon Code Jobs
     *
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getBulkCreateCouponCodeJobsAsync($fields_coupon_code_bulk_create_job = null, $filter = null, $page_cursor = null, $apiKey = null)
    {
        return $this->getBulkCreateCouponCodeJobsAsyncWithHttpInfo($fields_coupon_code_bulk_create_job, $filter, $page_cursor, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Alias of `getBulkCreateCouponCodeJobsAsync`
     *
     * @deprecated use `getBulkCreateCouponCodeJobsAsync` instead
     */
    public function getCouponCodeBulkCreateJobsAsync(...$args) {
        return $this->getBulkCreateCouponCodeJobsAsync(...$args);
    }

    /**
     * Operation getBulkCreateCouponCodeJobsAsyncWithHttpInfo
     *
     * Get Bulk Create Coupon Code Jobs
     *
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getBulkCreateCouponCodeJobsAsyncWithHttpInfo($fields_coupon_code_bulk_create_job = null, $filter = null, $page_cursor = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getBulkCreateCouponCodeJobsRequest($fields_coupon_code_bulk_create_job, $filter, $page_cursor, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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()
                    );
                }
            );
    }

    /**
     * Alias of `getBulkCreateCouponCodeJobsAsyncWithHttpInfo`
     *
     * @deprecated use `getBulkCreateCouponCodeJobsAsyncWithHttpInfo` instead
     */
    public function getCouponCodeBulkCreateJobsAsyncWithHttpInfo(...$args) {
        return $this->getBulkCreateCouponCodeJobsAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getBulkCreateCouponCodeJobs'
     *
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getBulkCreateCouponCodeJobsRequest($fields_coupon_code_bulk_create_job = null, $filter = null, $page_cursor = null, $apiKey = null)
    {

        $resourcePath = '/api/coupon-code-bulk-create-jobs';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon_code_bulk_create_job,
            'fields[coupon-code-bulk-create-job]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $filter,
            'filter', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page_cursor,
            'page[cursor]', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);




        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Alias of `getBulkCreateCouponCodeJobsRequest`
     *
     * @deprecated use `getBulkCreateCouponCodeJobsRequest` instead
     */
    public function getCouponCodeBulkCreateJobsRequest(...$args) {
        return $this->getBulkCreateCouponCodeJobsRequest(...$args);
    }

    /**
     * Operation getBulkCreateCouponCodesJob
     *
     * Get Bulk Create Coupon Codes Job
     *
     * @param  string $job_id ID of the job to retrieve. (required)
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getBulkCreateCouponCodesJob($job_id, $fields_coupon_code_bulk_create_job = null, $fields_coupon_code = null, $include = null, $apiKey = null)
    {
        list($response) = $this->getBulkCreateCouponCodesJobWithHttpInfo($job_id, $fields_coupon_code_bulk_create_job, $fields_coupon_code, $include, $apiKey);
        return $response;
    }

    /**
     * Alias of `getBulkCreateCouponCodesJob`
     *
     * @deprecated use `getBulkCreateCouponCodesJob` instead
     */
    public function getCouponCodeBulkCreateJob(...$args) {
        return $this->getBulkCreateCouponCodesJob(...$args);
    }

    /**
     * Operation getBulkCreateCouponCodesJobWithHttpInfo
     *
     * Get Bulk Create Coupon Codes Job
     *
     * @param  string $job_id ID of the job to retrieve. (required)
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getBulkCreateCouponCodesJobWithHttpInfo($job_id, $fields_coupon_code_bulk_create_job = null, $fields_coupon_code = null, $include = null, $apiKey = null)
    {
        $request = $this->getBulkCreateCouponCodesJobRequest($job_id, $fields_coupon_code_bulk_create_job, $fields_coupon_code, $include, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Alias of `getBulkCreateCouponCodesJobWithHttpInfo`
     *
     * @deprecated use `getBulkCreateCouponCodesJobWithHttpInfo` instead
     */
    public function getCouponCodeBulkCreateJobWithHttpInfo(...$args) {
        return $this->getBulkCreateCouponCodesJobWithHttpInfo(...$args);
    }

    /**
     * Operation getBulkCreateCouponCodesJobAsync
     *
     * Get Bulk Create Coupon Codes Job
     *
     * @param  string $job_id ID of the job to retrieve. (required)
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getBulkCreateCouponCodesJobAsync($job_id, $fields_coupon_code_bulk_create_job = null, $fields_coupon_code = null, $include = null, $apiKey = null)
    {
        return $this->getBulkCreateCouponCodesJobAsyncWithHttpInfo($job_id, $fields_coupon_code_bulk_create_job, $fields_coupon_code, $include, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Alias of `getBulkCreateCouponCodesJobAsync`
     *
     * @deprecated use `getBulkCreateCouponCodesJobAsync` instead
     */
    public function getCouponCodeBulkCreateJobAsync(...$args) {
        return $this->getBulkCreateCouponCodesJobAsync(...$args);
    }

    /**
     * Operation getBulkCreateCouponCodesJobAsyncWithHttpInfo
     *
     * Get Bulk Create Coupon Codes Job
     *
     * @param  string $job_id ID of the job to retrieve. (required)
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getBulkCreateCouponCodesJobAsyncWithHttpInfo($job_id, $fields_coupon_code_bulk_create_job = null, $fields_coupon_code = null, $include = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getBulkCreateCouponCodesJobRequest($job_id, $fields_coupon_code_bulk_create_job, $fields_coupon_code, $include, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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()
                    );
                }
            );
    }

    /**
     * Alias of `getBulkCreateCouponCodesJobAsyncWithHttpInfo`
     *
     * @deprecated use `getBulkCreateCouponCodesJobAsyncWithHttpInfo` instead
     */
    public function getCouponCodeBulkCreateJobAsyncWithHttpInfo(...$args) {
        return $this->getBulkCreateCouponCodesJobAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getBulkCreateCouponCodesJob'
     *
     * @param  string $job_id ID of the job to retrieve. (required)
     * @param  string[] $fields_coupon_code_bulk_create_job For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getBulkCreateCouponCodesJobRequest($job_id, $fields_coupon_code_bulk_create_job = null, $fields_coupon_code = null, $include = null, $apiKey = null)
    {
        // verify the required parameter 'job_id' is set
        if ($job_id === null || (is_array($job_id) && count($job_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $job_id when calling getBulkCreateCouponCodesJob'
            );
        }

        $resourcePath = '/api/coupon-code-bulk-create-jobs/{job_id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon_code_bulk_create_job,
            'fields[coupon-code-bulk-create-job]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon_code,
            'fields[coupon-code]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $include,
            'include', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);


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


        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Alias of `getBulkCreateCouponCodesJobRequest`
     *
     * @deprecated use `getBulkCreateCouponCodesJobRequest` instead
     */
    public function getCouponCodeBulkCreateJobRequest(...$args) {
        return $this->getBulkCreateCouponCodesJobRequest(...$args);
    }

    /**
     * Operation getCoupon
     *
     * Get Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getCoupon($id, $fields_coupon = null, $apiKey = null)
    {
        list($response) = $this->getCouponWithHttpInfo($id, $fields_coupon, $apiKey);
        return $response;
    }

    /**
     * Operation getCouponWithHttpInfo
     *
     * Get Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCouponWithHttpInfo($id, $fields_coupon = null, $apiKey = null)
    {
        $request = $this->getCouponRequest($id, $fields_coupon, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getCouponAsync
     *
     * Get Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponAsync($id, $fields_coupon = null, $apiKey = null)
    {
        return $this->getCouponAsyncWithHttpInfo($id, $fields_coupon, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCouponAsyncWithHttpInfo
     *
     * Get Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponAsyncWithHttpInfo($id, $fields_coupon = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCouponRequest($id, $fields_coupon, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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 'getCoupon'
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCouponRequest($id, $fields_coupon = null, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling getCoupon'
            );
        }

        $resourcePath = '/api/coupons/{id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon,
            'fields[coupon]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);


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


        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getCouponCode
     *
     * Get Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getCouponCode($id, $fields_coupon_code = null, $fields_coupon = null, $include = null, $apiKey = null)
    {
        list($response) = $this->getCouponCodeWithHttpInfo($id, $fields_coupon_code, $fields_coupon, $include, $apiKey);
        return $response;
    }

    /**
     * Operation getCouponCodeWithHttpInfo
     *
     * Get Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCouponCodeWithHttpInfo($id, $fields_coupon_code = null, $fields_coupon = null, $include = null, $apiKey = null)
    {
        $request = $this->getCouponCodeRequest($id, $fields_coupon_code, $fields_coupon, $include, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getCouponCodeAsync
     *
     * Get Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponCodeAsync($id, $fields_coupon_code = null, $fields_coupon = null, $include = null, $apiKey = null)
    {
        return $this->getCouponCodeAsyncWithHttpInfo($id, $fields_coupon_code, $fields_coupon, $include, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCouponCodeAsyncWithHttpInfo
     *
     * Get Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponCodeAsyncWithHttpInfo($id, $fields_coupon_code = null, $fields_coupon = null, $include = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCouponCodeRequest($id, $fields_coupon_code, $fields_coupon, $include, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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 'getCouponCode'
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCouponCodeRequest($id, $fields_coupon_code = null, $fields_coupon = null, $include = null, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling getCouponCode'
            );
        }

        $resourcePath = '/api/coupon-codes/{id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon_code,
            'fields[coupon-code]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon,
            'fields[coupon]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $include,
            'include', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);


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


        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getCouponCodeIdsForCoupon
     *
     * Get Coupon Code IDs for Coupon
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getCouponCodeIdsForCoupon($id, $filter = null, $page_cursor = null, $apiKey = null)
    {
        list($response) = $this->getCouponCodeIdsForCouponWithHttpInfo($id, $filter, $page_cursor, $apiKey);
        return $response;
    }

    /**
     * Alias of `getCouponCodeIdsForCoupon`
     *
     * @deprecated use `getCouponCodeIdsForCoupon` instead
     */
    public function getCouponCodeRelationshipsCoupon(...$args) {
        return $this->getCouponCodeIdsForCoupon(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCoupon`
     *
     * @deprecated use `getCouponCodeIdsForCoupon` instead
     */
    public function getCodeIdsForCoupon(...$args) {
        return $this->getCouponCodeIdsForCoupon(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCoupon`
     *
     * @deprecated use `getCouponCodeIdsForCoupon` instead
     */
    public function getCouponRelationshipsCodes(...$args) {
        return $this->getCouponCodeIdsForCoupon(...$args);
    }

    /**
     * Operation getCouponCodeIdsForCouponWithHttpInfo
     *
     * Get Coupon Code IDs for Coupon
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCouponCodeIdsForCouponWithHttpInfo($id, $filter = null, $page_cursor = null, $apiKey = null)
    {
        $request = $this->getCouponCodeIdsForCouponRequest($id, $filter, $page_cursor, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Alias of `getCouponCodeIdsForCouponWithHttpInfo`
     *
     * @deprecated use `getCouponCodeIdsForCouponWithHttpInfo` instead
     */
    public function getCouponCodeRelationshipsCouponWithHttpInfo(...$args) {
        return $this->getCouponCodeIdsForCouponWithHttpInfo(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCouponWithHttpInfo`
     *
     * @deprecated use `getCouponCodeIdsForCouponWithHttpInfo` instead
     */
    public function getCodeIdsForCouponWithHttpInfo(...$args) {
        return $this->getCouponCodeIdsForCouponWithHttpInfo(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCouponWithHttpInfo`
     *
     * @deprecated use `getCouponCodeIdsForCouponWithHttpInfo` instead
     */
    public function getCouponRelationshipsCodesWithHttpInfo(...$args) {
        return $this->getCouponCodeIdsForCouponWithHttpInfo(...$args);
    }

    /**
     * Operation getCouponCodeIdsForCouponAsync
     *
     * Get Coupon Code IDs for Coupon
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponCodeIdsForCouponAsync($id, $filter = null, $page_cursor = null, $apiKey = null)
    {
        return $this->getCouponCodeIdsForCouponAsyncWithHttpInfo($id, $filter, $page_cursor, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Alias of `getCouponCodeIdsForCouponAsync`
     *
     * @deprecated use `getCouponCodeIdsForCouponAsync` instead
     */
    public function getCouponCodeRelationshipsCouponAsync(...$args) {
        return $this->getCouponCodeIdsForCouponAsync(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCouponAsync`
     *
     * @deprecated use `getCouponCodeIdsForCouponAsync` instead
     */
    public function getCodeIdsForCouponAsync(...$args) {
        return $this->getCouponCodeIdsForCouponAsync(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCouponAsync`
     *
     * @deprecated use `getCouponCodeIdsForCouponAsync` instead
     */
    public function getCouponRelationshipsCodesAsync(...$args) {
        return $this->getCouponCodeIdsForCouponAsync(...$args);
    }

    /**
     * Operation getCouponCodeIdsForCouponAsyncWithHttpInfo
     *
     * Get Coupon Code IDs for Coupon
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponCodeIdsForCouponAsyncWithHttpInfo($id, $filter = null, $page_cursor = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCouponCodeIdsForCouponRequest($id, $filter, $page_cursor, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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()
                    );
                }
            );
    }

    /**
     * Alias of `getCouponCodeIdsForCouponAsyncWithHttpInfo`
     *
     * @deprecated use `getCouponCodeIdsForCouponAsyncWithHttpInfo` instead
     */
    public function getCouponCodeRelationshipsCouponAsyncWithHttpInfo(...$args) {
        return $this->getCouponCodeIdsForCouponAsyncWithHttpInfo(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCouponAsyncWithHttpInfo`
     *
     * @deprecated use `getCouponCodeIdsForCouponAsyncWithHttpInfo` instead
     */
    public function getCodeIdsForCouponAsyncWithHttpInfo(...$args) {
        return $this->getCouponCodeIdsForCouponAsyncWithHttpInfo(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCouponAsyncWithHttpInfo`
     *
     * @deprecated use `getCouponCodeIdsForCouponAsyncWithHttpInfo` instead
     */
    public function getCouponRelationshipsCodesAsyncWithHttpInfo(...$args) {
        return $this->getCouponCodeIdsForCouponAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getCouponCodeIdsForCoupon'
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCouponCodeIdsForCouponRequest($id, $filter = null, $page_cursor = null, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling getCouponCodeIdsForCoupon'
            );
        }

        $resourcePath = '/api/coupons/{id}/relationships/coupon-codes';
        $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(
            $page_cursor,
            'page[cursor]', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);


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


        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Alias of `getCouponCodeIdsForCouponRequest`
     *
     * @deprecated use `getCouponCodeIdsForCouponRequest` instead
     */
    public function getCouponCodeRelationshipsCouponRequest(...$args) {
        return $this->getCouponCodeIdsForCouponRequest(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCouponRequest`
     *
     * @deprecated use `getCouponCodeIdsForCouponRequest` instead
     */
    public function getCodeIdsForCouponRequest(...$args) {
        return $this->getCouponCodeIdsForCouponRequest(...$args);
    }

    /**
     * Alias of `getCouponCodeIdsForCouponRequest`
     *
     * @deprecated use `getCouponCodeIdsForCouponRequest` instead
     */
    public function getCouponRelationshipsCodesRequest(...$args) {
        return $this->getCouponCodeIdsForCouponRequest(...$args);
    }

    /**
     * Operation getCouponCodes
     *
     * Get Coupon Codes
     *
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getCouponCodes($filter, $fields_coupon_code = null, $fields_coupon = null, $include = null, $page_cursor = null, $apiKey = null)
    {
        list($response) = $this->getCouponCodesWithHttpInfo($filter, $fields_coupon_code, $fields_coupon, $include, $page_cursor, $apiKey);
        return $response;
    }

    /**
     * Operation getCouponCodesWithHttpInfo
     *
     * Get Coupon Codes
     *
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCouponCodesWithHttpInfo($filter, $fields_coupon_code = null, $fields_coupon = null, $include = null, $page_cursor = null, $apiKey = null)
    {
        $request = $this->getCouponCodesRequest($filter, $fields_coupon_code, $fields_coupon, $include, $page_cursor, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getCouponCodesAsync
     *
     * Get Coupon Codes
     *
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponCodesAsync($filter, $fields_coupon_code = null, $fields_coupon = null, $include = null, $page_cursor = null, $apiKey = null)
    {
        return $this->getCouponCodesAsyncWithHttpInfo($filter, $fields_coupon_code, $fields_coupon, $include, $page_cursor, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCouponCodesAsyncWithHttpInfo
     *
     * Get Coupon Codes
     *
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponCodesAsyncWithHttpInfo($filter, $fields_coupon_code = null, $fields_coupon = null, $include = null, $page_cursor = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCouponCodesRequest($filter, $fields_coupon_code, $fields_coupon, $include, $page_cursor, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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 'getCouponCodes'
     *
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $include For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#relationships (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCouponCodesRequest($filter, $fields_coupon_code = null, $fields_coupon = null, $include = null, $page_cursor = null, $apiKey = null)
    {
        // verify the required parameter 'filter' is set
        if ($filter === null || (is_array($filter) && count($filter) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $filter when calling getCouponCodes'
            );
        }

        $resourcePath = '/api/coupon-codes';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon_code,
            'fields[coupon-code]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon,
            'fields[coupon]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $filter,
            'filter', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $include,
            'include', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page_cursor,
            'page[cursor]', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);




        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getCouponCodesForCoupon
     *
     * Get Coupon Codes for Coupon
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getCouponCodesForCoupon($id, $fields_coupon_code = null, $filter = null, $page_cursor = null, $apiKey = null)
    {
        list($response) = $this->getCouponCodesForCouponWithHttpInfo($id, $fields_coupon_code, $filter, $page_cursor, $apiKey);
        return $response;
    }

    /**
     * Alias of `getCouponCodesForCoupon`
     *
     * @deprecated use `getCouponCodesForCoupon` instead
     */
    public function getCouponCouponCodes(...$args) {
        return $this->getCouponCodesForCoupon(...$args);
    }

    /**
     * Alias of `getCouponCodesForCoupon`
     *
     * @deprecated use `getCouponCodesForCoupon` instead
     */
    public function getCodesForCoupon(...$args) {
        return $this->getCouponCodesForCoupon(...$args);
    }

    /**
     * Operation getCouponCodesForCouponWithHttpInfo
     *
     * Get Coupon Codes for Coupon
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCouponCodesForCouponWithHttpInfo($id, $fields_coupon_code = null, $filter = null, $page_cursor = null, $apiKey = null)
    {
        $request = $this->getCouponCodesForCouponRequest($id, $fields_coupon_code, $filter, $page_cursor, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Alias of `getCouponCodesForCouponWithHttpInfo`
     *
     * @deprecated use `getCouponCodesForCouponWithHttpInfo` instead
     */
    public function getCouponCouponCodesWithHttpInfo(...$args) {
        return $this->getCouponCodesForCouponWithHttpInfo(...$args);
    }

    /**
     * Alias of `getCouponCodesForCouponWithHttpInfo`
     *
     * @deprecated use `getCouponCodesForCouponWithHttpInfo` instead
     */
    public function getCodesForCouponWithHttpInfo(...$args) {
        return $this->getCouponCodesForCouponWithHttpInfo(...$args);
    }

    /**
     * Operation getCouponCodesForCouponAsync
     *
     * Get Coupon Codes for Coupon
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponCodesForCouponAsync($id, $fields_coupon_code = null, $filter = null, $page_cursor = null, $apiKey = null)
    {
        return $this->getCouponCodesForCouponAsyncWithHttpInfo($id, $fields_coupon_code, $filter, $page_cursor, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Alias of `getCouponCodesForCouponAsync`
     *
     * @deprecated use `getCouponCodesForCouponAsync` instead
     */
    public function getCouponCouponCodesAsync(...$args) {
        return $this->getCouponCodesForCouponAsync(...$args);
    }

    /**
     * Alias of `getCouponCodesForCouponAsync`
     *
     * @deprecated use `getCouponCodesForCouponAsync` instead
     */
    public function getCodesForCouponAsync(...$args) {
        return $this->getCouponCodesForCouponAsync(...$args);
    }

    /**
     * Operation getCouponCodesForCouponAsyncWithHttpInfo
     *
     * Get Coupon Codes for Coupon
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponCodesForCouponAsyncWithHttpInfo($id, $fields_coupon_code = null, $filter = null, $page_cursor = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCouponCodesForCouponRequest($id, $fields_coupon_code, $filter, $page_cursor, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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()
                    );
                }
            );
    }

    /**
     * Alias of `getCouponCodesForCouponAsyncWithHttpInfo`
     *
     * @deprecated use `getCouponCodesForCouponAsyncWithHttpInfo` instead
     */
    public function getCouponCouponCodesAsyncWithHttpInfo(...$args) {
        return $this->getCouponCodesForCouponAsyncWithHttpInfo(...$args);
    }

    /**
     * Alias of `getCouponCodesForCouponAsyncWithHttpInfo`
     *
     * @deprecated use `getCouponCodesForCouponAsyncWithHttpInfo` instead
     */
    public function getCodesForCouponAsyncWithHttpInfo(...$args) {
        return $this->getCouponCodesForCouponAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getCouponCodesForCoupon'
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon_code For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $filter For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#filtering&lt;br&gt;Allowed field(s)/operator(s):&lt;br&gt;&#x60;expires_at&#x60;: &#x60;greater-or-equal&#x60;, &#x60;greater-than&#x60;, &#x60;less-or-equal&#x60;, &#x60;less-than&#x60;&lt;br&gt;&#x60;status&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;coupon.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60;&lt;br&gt;&#x60;profile.id&#x60;: &#x60;any&#x60;, &#x60;equals&#x60; (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCouponCodesForCouponRequest($id, $fields_coupon_code = null, $filter = null, $page_cursor = null, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling getCouponCodesForCoupon'
            );
        }

        $resourcePath = '/api/coupons/{id}/coupon-codes';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon_code,
            'fields[coupon-code]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $filter,
            'filter', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page_cursor,
            'page[cursor]', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);


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


        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Alias of `getCouponCodesForCouponRequest`
     *
     * @deprecated use `getCouponCodesForCouponRequest` instead
     */
    public function getCouponCouponCodesRequest(...$args) {
        return $this->getCouponCodesForCouponRequest(...$args);
    }

    /**
     * Alias of `getCouponCodesForCouponRequest`
     *
     * @deprecated use `getCouponCodesForCouponRequest` instead
     */
    public function getCodesForCouponRequest(...$args) {
        return $this->getCouponCodesForCouponRequest(...$args);
    }

    /**
     * Operation getCouponForCouponCode
     *
     * Get Coupon For Coupon Code
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getCouponForCouponCode($id, $fields_coupon = null, $apiKey = null)
    {
        list($response) = $this->getCouponForCouponCodeWithHttpInfo($id, $fields_coupon, $apiKey);
        return $response;
    }

    /**
     * Alias of `getCouponForCouponCode`
     *
     * @deprecated use `getCouponForCouponCode` instead
     */
    public function getCouponCodeCoupon(...$args) {
        return $this->getCouponForCouponCode(...$args);
    }

    /**
     * Operation getCouponForCouponCodeWithHttpInfo
     *
     * Get Coupon For Coupon Code
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCouponForCouponCodeWithHttpInfo($id, $fields_coupon = null, $apiKey = null)
    {
        $request = $this->getCouponForCouponCodeRequest($id, $fields_coupon, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Alias of `getCouponForCouponCodeWithHttpInfo`
     *
     * @deprecated use `getCouponForCouponCodeWithHttpInfo` instead
     */
    public function getCouponCodeCouponWithHttpInfo(...$args) {
        return $this->getCouponForCouponCodeWithHttpInfo(...$args);
    }

    /**
     * Operation getCouponForCouponCodeAsync
     *
     * Get Coupon For Coupon Code
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponForCouponCodeAsync($id, $fields_coupon = null, $apiKey = null)
    {
        return $this->getCouponForCouponCodeAsyncWithHttpInfo($id, $fields_coupon, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Alias of `getCouponForCouponCodeAsync`
     *
     * @deprecated use `getCouponForCouponCodeAsync` instead
     */
    public function getCouponCodeCouponAsync(...$args) {
        return $this->getCouponForCouponCodeAsync(...$args);
    }

    /**
     * Operation getCouponForCouponCodeAsyncWithHttpInfo
     *
     * Get Coupon For Coupon Code
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponForCouponCodeAsyncWithHttpInfo($id, $fields_coupon = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCouponForCouponCodeRequest($id, $fields_coupon, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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()
                    );
                }
            );
    }

    /**
     * Alias of `getCouponForCouponCodeAsyncWithHttpInfo`
     *
     * @deprecated use `getCouponForCouponCodeAsyncWithHttpInfo` instead
     */
    public function getCouponCodeCouponAsyncWithHttpInfo(...$args) {
        return $this->getCouponForCouponCodeAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getCouponForCouponCode'
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCouponForCouponCodeRequest($id, $fields_coupon = null, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling getCouponForCouponCode'
            );
        }

        $resourcePath = '/api/coupon-codes/{id}/coupon';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon,
            'fields[coupon]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);


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


        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Alias of `getCouponForCouponCodeRequest`
     *
     * @deprecated use `getCouponForCouponCodeRequest` instead
     */
    public function getCouponCodeCouponRequest(...$args) {
        return $this->getCouponForCouponCodeRequest(...$args);
    }

    /**
     * Operation getCouponIdForCouponCode
     *
     * Get Coupon ID for Coupon Code
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getCouponIdForCouponCode($id, $apiKey = null)
    {
        list($response) = $this->getCouponIdForCouponCodeWithHttpInfo($id, $apiKey);
        return $response;
    }

    /**
     * Alias of `getCouponIdForCouponCode`
     *
     * @deprecated use `getCouponIdForCouponCode` instead
     */
    public function getCouponRelationshipsCouponCodes(...$args) {
        return $this->getCouponIdForCouponCode(...$args);
    }

    /**
     * Operation getCouponIdForCouponCodeWithHttpInfo
     *
     * Get Coupon ID for Coupon Code
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCouponIdForCouponCodeWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->getCouponIdForCouponCodeRequest($id, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Alias of `getCouponIdForCouponCodeWithHttpInfo`
     *
     * @deprecated use `getCouponIdForCouponCodeWithHttpInfo` instead
     */
    public function getCouponRelationshipsCouponCodesWithHttpInfo(...$args) {
        return $this->getCouponIdForCouponCodeWithHttpInfo(...$args);
    }

    /**
     * Operation getCouponIdForCouponCodeAsync
     *
     * Get Coupon ID for Coupon Code
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponIdForCouponCodeAsync($id, $apiKey = null)
    {
        return $this->getCouponIdForCouponCodeAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Alias of `getCouponIdForCouponCodeAsync`
     *
     * @deprecated use `getCouponIdForCouponCodeAsync` instead
     */
    public function getCouponRelationshipsCouponCodesAsync(...$args) {
        return $this->getCouponIdForCouponCodeAsync(...$args);
    }

    /**
     * Operation getCouponIdForCouponCodeAsyncWithHttpInfo
     *
     * Get Coupon ID for Coupon Code
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponIdForCouponCodeAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCouponIdForCouponCodeRequest($id, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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()
                    );
                }
            );
    }

    /**
     * Alias of `getCouponIdForCouponCodeAsyncWithHttpInfo`
     *
     * @deprecated use `getCouponIdForCouponCodeAsyncWithHttpInfo` instead
     */
    public function getCouponRelationshipsCouponCodesAsyncWithHttpInfo(...$args) {
        return $this->getCouponIdForCouponCodeAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getCouponIdForCouponCode'
     *
     * @param  string $id The ID of the coupon to look up the relationship of. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCouponIdForCouponCodeRequest($id, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling getCouponIdForCouponCode'
            );
        }

        $resourcePath = '/api/coupon-codes/{id}/relationships/coupon';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Alias of `getCouponIdForCouponCodeRequest`
     *
     * @deprecated use `getCouponIdForCouponCodeRequest` instead
     */
    public function getCouponRelationshipsCouponCodesRequest(...$args) {
        return $this->getCouponIdForCouponCodeRequest(...$args);
    }

    /**
     * Operation getCoupons
     *
     * Get Coupons
     *
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getCoupons($fields_coupon = null, $page_cursor = null, $apiKey = null)
    {
        list($response) = $this->getCouponsWithHttpInfo($fields_coupon, $page_cursor, $apiKey);
        return $response;
    }

    /**
     * Operation getCouponsWithHttpInfo
     *
     * Get Coupons
     *
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCouponsWithHttpInfo($fields_coupon = null, $page_cursor = null, $apiKey = null)
    {
        $request = $this->getCouponsRequest($fields_coupon, $page_cursor, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getCouponsAsync
     *
     * Get Coupons
     *
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponsAsync($fields_coupon = null, $page_cursor = null, $apiKey = null)
    {
        return $this->getCouponsAsyncWithHttpInfo($fields_coupon, $page_cursor, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCouponsAsyncWithHttpInfo
     *
     * Get Coupons
     *
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCouponsAsyncWithHttpInfo($fields_coupon = null, $page_cursor = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCouponsRequest($fields_coupon, $page_cursor, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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 'getCoupons'
     *
     * @param  string[] $fields_coupon For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string $page_cursor For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#pagination (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCouponsRequest($fields_coupon = null, $page_cursor = null, $apiKey = null)
    {

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_coupon,
            'fields[coupon]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page_cursor,
            'page[cursor]', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);




        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.api+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.api+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' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation updateCoupon
     *
     * Update Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  \KlaviyoAPI\Model\CouponUpdateQuery $coupon_update_query coupon_update_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function updateCoupon($id, $coupon_update_query, $apiKey = null)
    {
        list($response) = $this->updateCouponWithHttpInfo($id, $coupon_update_query, $apiKey);
        return $response;
    }

    /**
     * Operation updateCouponWithHttpInfo
     *
     * Update Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  \KlaviyoAPI\Model\CouponUpdateQuery $coupon_update_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateCouponWithHttpInfo($id, $coupon_update_query, $apiKey = null)
    {
        $request = $this->updateCouponRequest($id, $coupon_update_query, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation updateCouponAsync
     *
     * Update Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  \KlaviyoAPI\Model\CouponUpdateQuery $coupon_update_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCouponAsync($id, $coupon_update_query, $apiKey = null)
    {
        return $this->updateCouponAsyncWithHttpInfo($id, $coupon_update_query, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateCouponAsyncWithHttpInfo
     *
     * Update Coupon
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  \KlaviyoAPI\Model\CouponUpdateQuery $coupon_update_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCouponAsyncWithHttpInfo($id, $coupon_update_query, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->updateCouponRequest($id, $coupon_update_query, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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 'updateCoupon'
     *
     * @param  string $id The internal id of a Coupon is equivalent to its external id stored within an integration. (required)
     * @param  \KlaviyoAPI\Model\CouponUpdateQuery $coupon_update_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updateCouponRequest($id, $coupon_update_query, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling updateCoupon'
            );
        }
        // verify the required parameter 'coupon_update_query' is set
        if ($coupon_update_query === null || (is_array($coupon_update_query) && count($coupon_update_query) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $coupon_update_query when calling updateCoupon'
            );
        }

        $resourcePath = '/api/coupons/{id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($coupon_update_query)) {
            if ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($coupon_update_query));
            } else {
                $httpBody = $coupon_update_query;
            }
        } 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 ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'PATCH',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation updateCouponCode
     *
     * Update Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  \KlaviyoAPI\Model\CouponCodeUpdateQuery $coupon_code_update_query coupon_code_update_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function updateCouponCode($id, $coupon_code_update_query, $apiKey = null)
    {
        list($response) = $this->updateCouponCodeWithHttpInfo($id, $coupon_code_update_query, $apiKey);
        return $response;
    }

    /**
     * Operation updateCouponCodeWithHttpInfo
     *
     * Update Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  \KlaviyoAPI\Model\CouponCodeUpdateQuery $coupon_code_update_query (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateCouponCodeWithHttpInfo($id, $coupon_code_update_query, $apiKey = null)
    {
        $request = $this->updateCouponCodeRequest($id, $coupon_code_update_query, $apiKey);

        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 ('array<string,mixed>' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('array&lt;string,mixed&gt;' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\KlaviyoAPI\Model\GetAccounts400Response' === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('\KlaviyoAPI\Model\GetAccounts400Response' !== 'string') {
                            $content = json_decode($content);
                        }
                    }


                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

            $returnType = 'array<string,mixed>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); //stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            $parsed_content = json_decode(json_encode($content), TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }

            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,mixed>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\KlaviyoAPI\Model\GetAccounts400Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation updateCouponCodeAsync
     *
     * Update Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  \KlaviyoAPI\Model\CouponCodeUpdateQuery $coupon_code_update_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCouponCodeAsync($id, $coupon_code_update_query, $apiKey = null)
    {
        return $this->updateCouponCodeAsyncWithHttpInfo($id, $coupon_code_update_query, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateCouponCodeAsyncWithHttpInfo
     *
     * Update Coupon Code
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  \KlaviyoAPI\Model\CouponCodeUpdateQuery $coupon_code_update_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCouponCodeAsyncWithHttpInfo($id, $coupon_code_update_query, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->updateCouponCodeRequest($id, $coupon_code_update_query, $apiKey);

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

                    $parsed_content = json_decode(json_encode($content), TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }

                    return [
                        $parsed_content,
                        $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 'updateCouponCode'
     *
     * @param  string $id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. (required)
     * @param  \KlaviyoAPI\Model\CouponCodeUpdateQuery $coupon_code_update_query (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updateCouponCodeRequest($id, $coupon_code_update_query, $apiKey = null)
    {
        // verify the required parameter 'id' is set
        if ($id === null || (is_array($id) && count($id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $id when calling updateCouponCode'
            );
        }
        // verify the required parameter 'coupon_code_update_query' is set
        if ($coupon_code_update_query === null || (is_array($coupon_code_update_query) && count($coupon_code_update_query) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $coupon_code_update_query when calling updateCouponCode'
            );
        }

        $resourcePath = '/api/coupon-codes/{id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


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

        // for model (json/xml)
        if (isset($coupon_code_update_query)) {
            if ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($coupon_code_update_query));
            } else {
                $httpBody = $coupon_code_update_query;
            }
        } 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 ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

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

        // this endpoint requires API key authentication
        if ($apiKey == null) {
            $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        } else {
            $apiKey = 'Klaviyo-API-Key '.$apiKey;
        }

        $headers['Authorization'] = $apiKey;


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

        $defaultHeaders['revision'] = ['2025-07-15'];

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

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