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

/**
 * MetricsApi Class Doc Comment
 *
 * @category Class
 * @package  KlaviyoAPI
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */
class MetricsApi
{
    /**
     * @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 createCustomMetric
     *
     * Create Custom Metric
     *
     * @param  \KlaviyoAPI\Model\CustomMetricCreateQuery $custom_metric_create_query Create a custom metric. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function createCustomMetric($custom_metric_create_query, $apiKey = null)
    {
        list($response) = $this->createCustomMetricWithHttpInfo($custom_metric_create_query, $apiKey);
        return $response;
    }

    /**
     * Operation createCustomMetricWithHttpInfo
     *
     * Create Custom Metric
     *
     * @param  \KlaviyoAPI\Model\CustomMetricCreateQuery $custom_metric_create_query Create a custom metric. (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 createCustomMetricWithHttpInfo($custom_metric_create_query, $apiKey = null)
    {
        $request = $this->createCustomMetricRequest($custom_metric_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 createCustomMetricAsync
     *
     * Create Custom Metric
     *
     * @param  \KlaviyoAPI\Model\CustomMetricCreateQuery $custom_metric_create_query Create a custom metric. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCustomMetricAsync($custom_metric_create_query, $apiKey = null)
    {
        return $this->createCustomMetricAsyncWithHttpInfo($custom_metric_create_query, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation createCustomMetricAsyncWithHttpInfo
     *
     * Create Custom Metric
     *
     * @param  \KlaviyoAPI\Model\CustomMetricCreateQuery $custom_metric_create_query Create a custom metric. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCustomMetricAsyncWithHttpInfo($custom_metric_create_query, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->createCustomMetricRequest($custom_metric_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 'createCustomMetric'
     *
     * @param  \KlaviyoAPI\Model\CustomMetricCreateQuery $custom_metric_create_query Create a custom metric. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function createCustomMetricRequest($custom_metric_create_query, $apiKey = null)
    {
        // verify the required parameter 'custom_metric_create_query' is set
        if ($custom_metric_create_query === null || (is_array($custom_metric_create_query) && count($custom_metric_create_query) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $custom_metric_create_query when calling createCustomMetric'
            );
        }

        $resourcePath = '/api/custom-metrics';
        $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($custom_metric_create_query)) {
            if ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($custom_metric_create_query));
            } else {
                $httpBody = $custom_metric_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 deleteCustomMetric
     *
     * Delete Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return void
     */
    public function deleteCustomMetric($id, $apiKey = null)
    {
        $this->deleteCustomMetricWithHttpInfo($id, $apiKey);
    }

    /**
     * Operation deleteCustomMetricWithHttpInfo
     *
     * Delete Custom Metric
     *
     * @param  string $id The ID of the custom metric (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 deleteCustomMetricWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->deleteCustomMetricRequest($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 deleteCustomMetricAsync
     *
     * Delete Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteCustomMetricAsync($id, $apiKey = null)
    {
        return $this->deleteCustomMetricAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation deleteCustomMetricAsyncWithHttpInfo
     *
     * Delete Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function deleteCustomMetricAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = '';
        $request = $this->deleteCustomMetricRequest($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 'deleteCustomMetric'
     *
     * @param  string $id The ID of the custom metric (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function deleteCustomMetricRequest($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 deleteCustomMetric'
            );
        }

        $resourcePath = '/api/custom-metrics/{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 getCustomMetric
     *
     * Get Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetric($id, $fields_custom_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        list($response) = $this->getCustomMetricWithHttpInfo($id, $fields_custom_metric, $fields_metric, $include, $apiKey);
        return $response;
    }

    /**
     * Operation getCustomMetricWithHttpInfo
     *
     * Get Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetricWithHttpInfo($id, $fields_custom_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $request = $this->getCustomMetricRequest($id, $fields_custom_metric, $fields_metric, $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 getCustomMetricAsync
     *
     * Get Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetricAsync($id, $fields_custom_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        return $this->getCustomMetricAsyncWithHttpInfo($id, $fields_custom_metric, $fields_metric, $include, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCustomMetricAsyncWithHttpInfo
     *
     * Get Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetricAsyncWithHttpInfo($id, $fields_custom_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCustomMetricRequest($id, $fields_custom_metric, $fields_metric, $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 'getCustomMetric'
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetricRequest($id, $fields_custom_metric = null, $fields_metric = 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 getCustomMetric'
            );
        }

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_custom_metric,
            'fields[custom-metric]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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 getCustomMetricForMappedMetric
     *
     * Get Custom Metric for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric 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 getCustomMetricForMappedMetric($id, $fields_custom_metric = null, $apiKey = null)
    {
        list($response) = $this->getCustomMetricForMappedMetricWithHttpInfo($id, $fields_custom_metric, $apiKey);
        return $response;
    }

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

    /**
     * Operation getCustomMetricForMappedMetricWithHttpInfo
     *
     * Get Custom Metric for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric 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 getCustomMetricForMappedMetricWithHttpInfo($id, $fields_custom_metric = null, $apiKey = null)
    {
        $request = $this->getCustomMetricForMappedMetricRequest($id, $fields_custom_metric, $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 `getCustomMetricForMappedMetricWithHttpInfo`
     *
     * @deprecated use `getCustomMetricForMappedMetricWithHttpInfo` instead
     */
    public function getMappedMetricCustomMetricWithHttpInfo(...$args) {
        return $this->getCustomMetricForMappedMetricWithHttpInfo(...$args);
    }

    /**
     * Operation getCustomMetricForMappedMetricAsync
     *
     * Get Custom Metric for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric 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 getCustomMetricForMappedMetricAsync($id, $fields_custom_metric = null, $apiKey = null)
    {
        return $this->getCustomMetricForMappedMetricAsyncWithHttpInfo($id, $fields_custom_metric, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

    /**
     * Operation getCustomMetricForMappedMetricAsyncWithHttpInfo
     *
     * Get Custom Metric for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric 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 getCustomMetricForMappedMetricAsyncWithHttpInfo($id, $fields_custom_metric = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCustomMetricForMappedMetricRequest($id, $fields_custom_metric, $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 `getCustomMetricForMappedMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getCustomMetricForMappedMetricAsyncWithHttpInfo` instead
     */
    public function getMappedMetricCustomMetricAsyncWithHttpInfo(...$args) {
        return $this->getCustomMetricForMappedMetricAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getCustomMetricForMappedMetric'
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric 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 getCustomMetricForMappedMetricRequest($id, $fields_custom_metric = 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 getCustomMetricForMappedMetric'
            );
        }

        $resourcePath = '/api/mapped-metrics/{id}/custom-metric';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_custom_metric,
            'fields[custom-metric]', // 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 `getCustomMetricForMappedMetricRequest`
     *
     * @deprecated use `getCustomMetricForMappedMetricRequest` instead
     */
    public function getMappedMetricCustomMetricRequest(...$args) {
        return $this->getCustomMetricForMappedMetricRequest(...$args);
    }

    /**
     * Operation getCustomMetricIdForMappedMetric
     *
     * Get Custom Metric ID for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getCustomMetricIdForMappedMetric($id, $apiKey = null)
    {
        list($response) = $this->getCustomMetricIdForMappedMetricWithHttpInfo($id, $apiKey);
        return $response;
    }

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

    /**
     * Operation getCustomMetricIdForMappedMetricWithHttpInfo
     *
     * Get Custom Metric ID for Mapped Metric
     *
     * @param  string $id The type of mapping. (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 getCustomMetricIdForMappedMetricWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->getCustomMetricIdForMappedMetricRequest($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 `getCustomMetricIdForMappedMetricWithHttpInfo`
     *
     * @deprecated use `getCustomMetricIdForMappedMetricWithHttpInfo` instead
     */
    public function getMappedMetricRelationshipsCustomMetricWithHttpInfo(...$args) {
        return $this->getCustomMetricIdForMappedMetricWithHttpInfo(...$args);
    }

    /**
     * Operation getCustomMetricIdForMappedMetricAsync
     *
     * Get Custom Metric ID for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCustomMetricIdForMappedMetricAsync($id, $apiKey = null)
    {
        return $this->getCustomMetricIdForMappedMetricAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

    /**
     * Operation getCustomMetricIdForMappedMetricAsyncWithHttpInfo
     *
     * Get Custom Metric ID for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCustomMetricIdForMappedMetricAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCustomMetricIdForMappedMetricRequest($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 `getCustomMetricIdForMappedMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getCustomMetricIdForMappedMetricAsyncWithHttpInfo` instead
     */
    public function getMappedMetricRelationshipsCustomMetricAsyncWithHttpInfo(...$args) {
        return $this->getCustomMetricIdForMappedMetricAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getCustomMetricIdForMappedMetric'
     *
     * @param  string $id The type of mapping. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getCustomMetricIdForMappedMetricRequest($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 getCustomMetricIdForMappedMetric'
            );
        }

        $resourcePath = '/api/mapped-metrics/{id}/relationships/custom-metric';
        $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 `getCustomMetricIdForMappedMetricRequest`
     *
     * @deprecated use `getCustomMetricIdForMappedMetricRequest` instead
     */
    public function getMappedMetricRelationshipsCustomMetricRequest(...$args) {
        return $this->getCustomMetricIdForMappedMetricRequest(...$args);
    }

    /**
     * Operation getCustomMetrics
     *
     * Get Custom Metrics
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetrics($fields_custom_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        list($response) = $this->getCustomMetricsWithHttpInfo($fields_custom_metric, $fields_metric, $include, $apiKey);
        return $response;
    }

    /**
     * Operation getCustomMetricsWithHttpInfo
     *
     * Get Custom Metrics
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetricsWithHttpInfo($fields_custom_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $request = $this->getCustomMetricsRequest($fields_custom_metric, $fields_metric, $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 getCustomMetricsAsync
     *
     * Get Custom Metrics
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetricsAsync($fields_custom_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        return $this->getCustomMetricsAsyncWithHttpInfo($fields_custom_metric, $fields_metric, $include, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCustomMetricsAsyncWithHttpInfo
     *
     * Get Custom Metrics
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetricsAsyncWithHttpInfo($fields_custom_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getCustomMetricsRequest($fields_custom_metric, $fields_metric, $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 'getCustomMetrics'
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getCustomMetricsRequest($fields_custom_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_custom_metric,
            'fields[custom-metric]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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
        ) ?? []);




        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 getFlowsTriggeredByMetric
     *
     * Get Flows Triggered by Metric
     *
     * @param  string $id  (required)
     * @param  string[] $fields_flow 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 getFlowsTriggeredByMetric($id, $fields_flow = null, $apiKey = null)
    {
        list($response) = $this->getFlowsTriggeredByMetricWithHttpInfo($id, $fields_flow, $apiKey);
        return $response;
    }

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

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

    /**
     * Operation getFlowsTriggeredByMetricWithHttpInfo
     *
     * Get Flows Triggered by Metric
     *
     * @param  string $id  (required)
     * @param  string[] $fields_flow 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 getFlowsTriggeredByMetricWithHttpInfo($id, $fields_flow = null, $apiKey = null)
    {
        $request = $this->getFlowsTriggeredByMetricRequest($id, $fields_flow, $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 `getFlowsTriggeredByMetricWithHttpInfo`
     *
     * @deprecated use `getFlowsTriggeredByMetricWithHttpInfo` instead
     */
    public function getFlowTriggersForMetricWithHttpInfo(...$args) {
        return $this->getFlowsTriggeredByMetricWithHttpInfo(...$args);
    }

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

    /**
     * Operation getFlowsTriggeredByMetricAsync
     *
     * Get Flows Triggered by Metric
     *
     * @param  string $id  (required)
     * @param  string[] $fields_flow 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 getFlowsTriggeredByMetricAsync($id, $fields_flow = null, $apiKey = null)
    {
        return $this->getFlowsTriggeredByMetricAsyncWithHttpInfo($id, $fields_flow, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

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

    /**
     * Operation getFlowsTriggeredByMetricAsyncWithHttpInfo
     *
     * Get Flows Triggered by Metric
     *
     * @param  string $id  (required)
     * @param  string[] $fields_flow 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 getFlowsTriggeredByMetricAsyncWithHttpInfo($id, $fields_flow = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getFlowsTriggeredByMetricRequest($id, $fields_flow, $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 `getFlowsTriggeredByMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getFlowsTriggeredByMetricAsyncWithHttpInfo` instead
     */
    public function getFlowTriggersForMetricAsyncWithHttpInfo(...$args) {
        return $this->getFlowsTriggeredByMetricAsyncWithHttpInfo(...$args);
    }

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

    /**
     * Create request for operation 'getFlowsTriggeredByMetric'
     *
     * @param  string $id  (required)
     * @param  string[] $fields_flow 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 getFlowsTriggeredByMetricRequest($id, $fields_flow = 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 getFlowsTriggeredByMetric'
            );
        }

        $resourcePath = '/api/metrics/{id}/flow-triggers';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_flow,
            'fields[flow]', // 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 `getFlowsTriggeredByMetricRequest`
     *
     * @deprecated use `getFlowsTriggeredByMetricRequest` instead
     */
    public function getFlowTriggersForMetricRequest(...$args) {
        return $this->getFlowsTriggeredByMetricRequest(...$args);
    }

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

    /**
     * Operation getIdsForFlowsTriggeredByMetric
     *
     * Get IDs for Flows Triggered by Metric
     *
     * @param  string $id  (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getIdsForFlowsTriggeredByMetric($id, $apiKey = null)
    {
        list($response) = $this->getIdsForFlowsTriggeredByMetricWithHttpInfo($id, $apiKey);
        return $response;
    }

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

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

    /**
     * Operation getIdsForFlowsTriggeredByMetricWithHttpInfo
     *
     * Get IDs for Flows Triggered by Metric
     *
     * @param  string $id  (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 getIdsForFlowsTriggeredByMetricWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->getIdsForFlowsTriggeredByMetricRequest($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 `getIdsForFlowsTriggeredByMetricWithHttpInfo`
     *
     * @deprecated use `getIdsForFlowsTriggeredByMetricWithHttpInfo` instead
     */
    public function getFlowTriggerIdsForMetricWithHttpInfo(...$args) {
        return $this->getIdsForFlowsTriggeredByMetricWithHttpInfo(...$args);
    }

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

    /**
     * Operation getIdsForFlowsTriggeredByMetricAsync
     *
     * Get IDs for Flows Triggered by Metric
     *
     * @param  string $id  (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getIdsForFlowsTriggeredByMetricAsync($id, $apiKey = null)
    {
        return $this->getIdsForFlowsTriggeredByMetricAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

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

    /**
     * Operation getIdsForFlowsTriggeredByMetricAsyncWithHttpInfo
     *
     * Get IDs for Flows Triggered by Metric
     *
     * @param  string $id  (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getIdsForFlowsTriggeredByMetricAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getIdsForFlowsTriggeredByMetricRequest($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 `getIdsForFlowsTriggeredByMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getIdsForFlowsTriggeredByMetricAsyncWithHttpInfo` instead
     */
    public function getFlowTriggerIdsForMetricAsyncWithHttpInfo(...$args) {
        return $this->getIdsForFlowsTriggeredByMetricAsyncWithHttpInfo(...$args);
    }

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

    /**
     * Create request for operation 'getIdsForFlowsTriggeredByMetric'
     *
     * @param  string $id  (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getIdsForFlowsTriggeredByMetricRequest($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 getIdsForFlowsTriggeredByMetric'
            );
        }

        $resourcePath = '/api/metrics/{id}/relationships/flow-triggers';
        $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 `getIdsForFlowsTriggeredByMetricRequest`
     *
     * @deprecated use `getIdsForFlowsTriggeredByMetricRequest` instead
     */
    public function getFlowTriggerIdsForMetricRequest(...$args) {
        return $this->getIdsForFlowsTriggeredByMetricRequest(...$args);
    }

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

    /**
     * Operation getMappedMetric
     *
     * Get Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetric($id, $fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        list($response) = $this->getMappedMetricWithHttpInfo($id, $fields_custom_metric, $fields_mapped_metric, $fields_metric, $include, $apiKey);
        return $response;
    }

    /**
     * Operation getMappedMetricWithHttpInfo
     *
     * Get Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetricWithHttpInfo($id, $fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $request = $this->getMappedMetricRequest($id, $fields_custom_metric, $fields_mapped_metric, $fields_metric, $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 getMappedMetricAsync
     *
     * Get Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetricAsync($id, $fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        return $this->getMappedMetricAsyncWithHttpInfo($id, $fields_custom_metric, $fields_mapped_metric, $fields_metric, $include, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getMappedMetricAsyncWithHttpInfo
     *
     * Get Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetricAsyncWithHttpInfo($id, $fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMappedMetricRequest($id, $fields_custom_metric, $fields_mapped_metric, $fields_metric, $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 'getMappedMetric'
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetricRequest($id, $fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = 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 getMappedMetric'
            );
        }

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_custom_metric,
            'fields[custom-metric]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_mapped_metric,
            'fields[mapped-metric]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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 getMappedMetrics
     *
     * Get Mapped Metrics
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetrics($fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        list($response) = $this->getMappedMetricsWithHttpInfo($fields_custom_metric, $fields_mapped_metric, $fields_metric, $include, $apiKey);
        return $response;
    }

    /**
     * Operation getMappedMetricsWithHttpInfo
     *
     * Get Mapped Metrics
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetricsWithHttpInfo($fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $request = $this->getMappedMetricsRequest($fields_custom_metric, $fields_mapped_metric, $fields_metric, $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 getMappedMetricsAsync
     *
     * Get Mapped Metrics
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetricsAsync($fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        return $this->getMappedMetricsAsyncWithHttpInfo($fields_custom_metric, $fields_mapped_metric, $fields_metric, $include, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getMappedMetricsAsyncWithHttpInfo
     *
     * Get Mapped Metrics
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetricsAsyncWithHttpInfo($fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMappedMetricsRequest($fields_custom_metric, $fields_mapped_metric, $fields_metric, $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 'getMappedMetrics'
     *
     * @param  string[] $fields_custom_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_mapped_metric For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMappedMetricsRequest($fields_custom_metric = null, $fields_mapped_metric = null, $fields_metric = null, $include = null, $apiKey = null)
    {

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_custom_metric,
            'fields[custom-metric]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_mapped_metric,
            'fields[mapped-metric]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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
        ) ?? []);




        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 getMetric
     *
     * Get Metric
     *
     * @param  string $id Metric ID (required)
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetric($id, $fields_flow = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        list($response) = $this->getMetricWithHttpInfo($id, $fields_flow, $fields_metric, $include, $apiKey);
        return $response;
    }

    /**
     * Operation getMetricWithHttpInfo
     *
     * Get Metric
     *
     * @param  string $id Metric ID (required)
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetricWithHttpInfo($id, $fields_flow = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $request = $this->getMetricRequest($id, $fields_flow, $fields_metric, $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 getMetricAsync
     *
     * Get Metric
     *
     * @param  string $id Metric ID (required)
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetricAsync($id, $fields_flow = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        return $this->getMetricAsyncWithHttpInfo($id, $fields_flow, $fields_metric, $include, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getMetricAsyncWithHttpInfo
     *
     * Get Metric
     *
     * @param  string $id Metric ID (required)
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetricAsyncWithHttpInfo($id, $fields_flow = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMetricRequest($id, $fields_flow, $fields_metric, $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 'getMetric'
     *
     * @param  string $id Metric ID (required)
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetricRequest($id, $fields_flow = null, $fields_metric = 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 getMetric'
            );
        }

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_flow,
            'fields[flow]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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 getMetricForMappedMetric
     *
     * Get Metric for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_metric 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 getMetricForMappedMetric($id, $fields_metric = null, $apiKey = null)
    {
        list($response) = $this->getMetricForMappedMetricWithHttpInfo($id, $fields_metric, $apiKey);
        return $response;
    }

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

    /**
     * Operation getMetricForMappedMetricWithHttpInfo
     *
     * Get Metric for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_metric 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 getMetricForMappedMetricWithHttpInfo($id, $fields_metric = null, $apiKey = null)
    {
        $request = $this->getMetricForMappedMetricRequest($id, $fields_metric, $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 `getMetricForMappedMetricWithHttpInfo`
     *
     * @deprecated use `getMetricForMappedMetricWithHttpInfo` instead
     */
    public function getMappedMetricMetricWithHttpInfo(...$args) {
        return $this->getMetricForMappedMetricWithHttpInfo(...$args);
    }

    /**
     * Operation getMetricForMappedMetricAsync
     *
     * Get Metric for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_metric 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 getMetricForMappedMetricAsync($id, $fields_metric = null, $apiKey = null)
    {
        return $this->getMetricForMappedMetricAsyncWithHttpInfo($id, $fields_metric, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

    /**
     * Operation getMetricForMappedMetricAsyncWithHttpInfo
     *
     * Get Metric for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_metric 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 getMetricForMappedMetricAsyncWithHttpInfo($id, $fields_metric = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMetricForMappedMetricRequest($id, $fields_metric, $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 `getMetricForMappedMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getMetricForMappedMetricAsyncWithHttpInfo` instead
     */
    public function getMappedMetricMetricAsyncWithHttpInfo(...$args) {
        return $this->getMetricForMappedMetricAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getMetricForMappedMetric'
     *
     * @param  string $id The type of mapping. (required)
     * @param  string[] $fields_metric 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 getMetricForMappedMetricRequest($id, $fields_metric = 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 getMetricForMappedMetric'
            );
        }

        $resourcePath = '/api/mapped-metrics/{id}/metric';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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 `getMetricForMappedMetricRequest`
     *
     * @deprecated use `getMetricForMappedMetricRequest` instead
     */
    public function getMappedMetricMetricRequest(...$args) {
        return $this->getMetricForMappedMetricRequest(...$args);
    }

    /**
     * Operation getMetricForMetricProperty
     *
     * Get Metric for Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $fields_metric 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 getMetricForMetricProperty($id, $fields_metric = null, $apiKey = null)
    {
        list($response) = $this->getMetricForMetricPropertyWithHttpInfo($id, $fields_metric, $apiKey);
        return $response;
    }

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

    /**
     * Operation getMetricForMetricPropertyWithHttpInfo
     *
     * Get Metric for Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $fields_metric 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 getMetricForMetricPropertyWithHttpInfo($id, $fields_metric = null, $apiKey = null)
    {
        $request = $this->getMetricForMetricPropertyRequest($id, $fields_metric, $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 `getMetricForMetricPropertyWithHttpInfo`
     *
     * @deprecated use `getMetricForMetricPropertyWithHttpInfo` instead
     */
    public function getMetricPropertyMetricWithHttpInfo(...$args) {
        return $this->getMetricForMetricPropertyWithHttpInfo(...$args);
    }

    /**
     * Operation getMetricForMetricPropertyAsync
     *
     * Get Metric for Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $fields_metric 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 getMetricForMetricPropertyAsync($id, $fields_metric = null, $apiKey = null)
    {
        return $this->getMetricForMetricPropertyAsyncWithHttpInfo($id, $fields_metric, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

    /**
     * Operation getMetricForMetricPropertyAsyncWithHttpInfo
     *
     * Get Metric for Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $fields_metric 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 getMetricForMetricPropertyAsyncWithHttpInfo($id, $fields_metric = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMetricForMetricPropertyRequest($id, $fields_metric, $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 `getMetricForMetricPropertyAsyncWithHttpInfo`
     *
     * @deprecated use `getMetricForMetricPropertyAsyncWithHttpInfo` instead
     */
    public function getMetricPropertyMetricAsyncWithHttpInfo(...$args) {
        return $this->getMetricForMetricPropertyAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getMetricForMetricProperty'
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $fields_metric 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 getMetricForMetricPropertyRequest($id, $fields_metric = 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 getMetricForMetricProperty'
            );
        }

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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 `getMetricForMetricPropertyRequest`
     *
     * @deprecated use `getMetricForMetricPropertyRequest` instead
     */
    public function getMetricPropertyMetricRequest(...$args) {
        return $this->getMetricForMetricPropertyRequest(...$args);
    }

    /**
     * Operation getMetricIdForMappedMetric
     *
     * Get Metric ID for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getMetricIdForMappedMetric($id, $apiKey = null)
    {
        list($response) = $this->getMetricIdForMappedMetricWithHttpInfo($id, $apiKey);
        return $response;
    }

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

    /**
     * Operation getMetricIdForMappedMetricWithHttpInfo
     *
     * Get Metric ID for Mapped Metric
     *
     * @param  string $id The type of mapping. (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 getMetricIdForMappedMetricWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->getMetricIdForMappedMetricRequest($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 `getMetricIdForMappedMetricWithHttpInfo`
     *
     * @deprecated use `getMetricIdForMappedMetricWithHttpInfo` instead
     */
    public function getMappedMetricRelationshipsMetricWithHttpInfo(...$args) {
        return $this->getMetricIdForMappedMetricWithHttpInfo(...$args);
    }

    /**
     * Operation getMetricIdForMappedMetricAsync
     *
     * Get Metric ID for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getMetricIdForMappedMetricAsync($id, $apiKey = null)
    {
        return $this->getMetricIdForMappedMetricAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

    /**
     * Operation getMetricIdForMappedMetricAsyncWithHttpInfo
     *
     * Get Metric ID for Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getMetricIdForMappedMetricAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMetricIdForMappedMetricRequest($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 `getMetricIdForMappedMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getMetricIdForMappedMetricAsyncWithHttpInfo` instead
     */
    public function getMappedMetricRelationshipsMetricAsyncWithHttpInfo(...$args) {
        return $this->getMetricIdForMappedMetricAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getMetricIdForMappedMetric'
     *
     * @param  string $id The type of mapping. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getMetricIdForMappedMetricRequest($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 getMetricIdForMappedMetric'
            );
        }

        $resourcePath = '/api/mapped-metrics/{id}/relationships/metric';
        $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 `getMetricIdForMappedMetricRequest`
     *
     * @deprecated use `getMetricIdForMappedMetricRequest` instead
     */
    public function getMappedMetricRelationshipsMetricRequest(...$args) {
        return $this->getMetricIdForMappedMetricRequest(...$args);
    }

    /**
     * Operation getMetricIdForMetricProperty
     *
     * Get Metric ID for Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getMetricIdForMetricProperty($id, $apiKey = null)
    {
        list($response) = $this->getMetricIdForMetricPropertyWithHttpInfo($id, $apiKey);
        return $response;
    }

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

    /**
     * Operation getMetricIdForMetricPropertyWithHttpInfo
     *
     * Get Metric ID for Metric Property
     *
     * @param  string $id The ID of the metric property (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 getMetricIdForMetricPropertyWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->getMetricIdForMetricPropertyRequest($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 `getMetricIdForMetricPropertyWithHttpInfo`
     *
     * @deprecated use `getMetricIdForMetricPropertyWithHttpInfo` instead
     */
    public function getMetricPropertyRelationshipsMetricWithHttpInfo(...$args) {
        return $this->getMetricIdForMetricPropertyWithHttpInfo(...$args);
    }

    /**
     * Operation getMetricIdForMetricPropertyAsync
     *
     * Get Metric ID for Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getMetricIdForMetricPropertyAsync($id, $apiKey = null)
    {
        return $this->getMetricIdForMetricPropertyAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

    /**
     * Operation getMetricIdForMetricPropertyAsyncWithHttpInfo
     *
     * Get Metric ID for Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getMetricIdForMetricPropertyAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMetricIdForMetricPropertyRequest($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 `getMetricIdForMetricPropertyAsyncWithHttpInfo`
     *
     * @deprecated use `getMetricIdForMetricPropertyAsyncWithHttpInfo` instead
     */
    public function getMetricPropertyRelationshipsMetricAsyncWithHttpInfo(...$args) {
        return $this->getMetricIdForMetricPropertyAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getMetricIdForMetricProperty'
     *
     * @param  string $id The ID of the metric property (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getMetricIdForMetricPropertyRequest($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 getMetricIdForMetricProperty'
            );
        }

        $resourcePath = '/api/metric-properties/{id}/relationships/metric';
        $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 `getMetricIdForMetricPropertyRequest`
     *
     * @deprecated use `getMetricIdForMetricPropertyRequest` instead
     */
    public function getMetricPropertyRelationshipsMetricRequest(...$args) {
        return $this->getMetricIdForMetricPropertyRequest(...$args);
    }

    /**
     * Operation getMetricIdsForCustomMetric
     *
     * Get Metric IDs for Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getMetricIdsForCustomMetric($id, $apiKey = null)
    {
        list($response) = $this->getMetricIdsForCustomMetricWithHttpInfo($id, $apiKey);
        return $response;
    }

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

    /**
     * Operation getMetricIdsForCustomMetricWithHttpInfo
     *
     * Get Metric IDs for Custom Metric
     *
     * @param  string $id The ID of the custom metric (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 getMetricIdsForCustomMetricWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->getMetricIdsForCustomMetricRequest($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 `getMetricIdsForCustomMetricWithHttpInfo`
     *
     * @deprecated use `getMetricIdsForCustomMetricWithHttpInfo` instead
     */
    public function getCustomMetricRelationshipsMetricsWithHttpInfo(...$args) {
        return $this->getMetricIdsForCustomMetricWithHttpInfo(...$args);
    }

    /**
     * Operation getMetricIdsForCustomMetricAsync
     *
     * Get Metric IDs for Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getMetricIdsForCustomMetricAsync($id, $apiKey = null)
    {
        return $this->getMetricIdsForCustomMetricAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

    /**
     * Operation getMetricIdsForCustomMetricAsyncWithHttpInfo
     *
     * Get Metric IDs for Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getMetricIdsForCustomMetricAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMetricIdsForCustomMetricRequest($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 `getMetricIdsForCustomMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getMetricIdsForCustomMetricAsyncWithHttpInfo` instead
     */
    public function getCustomMetricRelationshipsMetricsAsyncWithHttpInfo(...$args) {
        return $this->getMetricIdsForCustomMetricAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getMetricIdsForCustomMetric'
     *
     * @param  string $id The ID of the custom metric (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getMetricIdsForCustomMetricRequest($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 getMetricIdsForCustomMetric'
            );
        }

        $resourcePath = '/api/custom-metrics/{id}/relationships/metrics';
        $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 `getMetricIdsForCustomMetricRequest`
     *
     * @deprecated use `getMetricIdsForCustomMetricRequest` instead
     */
    public function getCustomMetricRelationshipsMetricsRequest(...$args) {
        return $this->getMetricIdsForCustomMetricRequest(...$args);
    }

    /**
     * Operation getMetricProperty
     *
     * Get Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetricProperty($id, $additional_fields_metric_property = null, $fields_metric_property = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        list($response) = $this->getMetricPropertyWithHttpInfo($id, $additional_fields_metric_property, $fields_metric_property, $fields_metric, $include, $apiKey);
        return $response;
    }

    /**
     * Operation getMetricPropertyWithHttpInfo
     *
     * Get Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetricPropertyWithHttpInfo($id, $additional_fields_metric_property = null, $fields_metric_property = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $request = $this->getMetricPropertyRequest($id, $additional_fields_metric_property, $fields_metric_property, $fields_metric, $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 getMetricPropertyAsync
     *
     * Get Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetricPropertyAsync($id, $additional_fields_metric_property = null, $fields_metric_property = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        return $this->getMetricPropertyAsyncWithHttpInfo($id, $additional_fields_metric_property, $fields_metric_property, $fields_metric, $include, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getMetricPropertyAsyncWithHttpInfo
     *
     * Get Metric Property
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetricPropertyAsyncWithHttpInfo($id, $additional_fields_metric_property = null, $fields_metric_property = null, $fields_metric = null, $include = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMetricPropertyRequest($id, $additional_fields_metric_property, $fields_metric_property, $fields_metric, $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 'getMetricProperty'
     *
     * @param  string $id The ID of the metric property (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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 getMetricPropertyRequest($id, $additional_fields_metric_property = null, $fields_metric_property = null, $fields_metric = 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 getMetricProperty'
            );
        }

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $additional_fields_metric_property,
            'additional-fields[metric-property]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric_property,
            'fields[metric-property]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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 getMetrics
     *
     * Get Metrics
     *
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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;integration.name&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;integration.category&#x60;: &#x60;equals&#x60; (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 getMetrics($fields_flow = null, $fields_metric = null, $filter = null, $include = null, $page_cursor = null, $apiKey = null)
    {
        list($response) = $this->getMetricsWithHttpInfo($fields_flow, $fields_metric, $filter, $include, $page_cursor, $apiKey);
        return $response;
    }

    /**
     * Operation getMetricsWithHttpInfo
     *
     * Get Metrics
     *
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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;integration.name&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;integration.category&#x60;: &#x60;equals&#x60; (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 getMetricsWithHttpInfo($fields_flow = null, $fields_metric = null, $filter = null, $include = null, $page_cursor = null, $apiKey = null)
    {
        $request = $this->getMetricsRequest($fields_flow, $fields_metric, $filter, $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 getMetricsAsync
     *
     * Get Metrics
     *
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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;integration.name&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;integration.category&#x60;: &#x60;equals&#x60; (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 getMetricsAsync($fields_flow = null, $fields_metric = null, $filter = null, $include = null, $page_cursor = null, $apiKey = null)
    {
        return $this->getMetricsAsyncWithHttpInfo($fields_flow, $fields_metric, $filter, $include, $page_cursor, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getMetricsAsyncWithHttpInfo
     *
     * Get Metrics
     *
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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;integration.name&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;integration.category&#x60;: &#x60;equals&#x60; (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 getMetricsAsyncWithHttpInfo($fields_flow = null, $fields_metric = null, $filter = null, $include = null, $page_cursor = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMetricsRequest($fields_flow, $fields_metric, $filter, $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 'getMetrics'
     *
     * @param  string[] $fields_flow For more information please visit https://developers.klaviyo.com/en/v2025-07-15/reference/api-overview#sparse-fieldsets (optional)
     * @param  string[] $fields_metric 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;integration.name&#x60;: &#x60;equals&#x60;&lt;br&gt;&#x60;integration.category&#x60;: &#x60;equals&#x60; (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 getMetricsRequest($fields_flow = null, $fields_metric = null, $filter = null, $include = null, $page_cursor = null, $apiKey = null)
    {

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_flow,
            'fields[flow]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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(
            $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 getMetricsForCustomMetric
     *
     * Get Metrics for Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_metric 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 getMetricsForCustomMetric($id, $fields_metric = null, $apiKey = null)
    {
        list($response) = $this->getMetricsForCustomMetricWithHttpInfo($id, $fields_metric, $apiKey);
        return $response;
    }

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

    /**
     * Operation getMetricsForCustomMetricWithHttpInfo
     *
     * Get Metrics for Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_metric 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 getMetricsForCustomMetricWithHttpInfo($id, $fields_metric = null, $apiKey = null)
    {
        $request = $this->getMetricsForCustomMetricRequest($id, $fields_metric, $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 `getMetricsForCustomMetricWithHttpInfo`
     *
     * @deprecated use `getMetricsForCustomMetricWithHttpInfo` instead
     */
    public function getCustomMetricMetricsWithHttpInfo(...$args) {
        return $this->getMetricsForCustomMetricWithHttpInfo(...$args);
    }

    /**
     * Operation getMetricsForCustomMetricAsync
     *
     * Get Metrics for Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_metric 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 getMetricsForCustomMetricAsync($id, $fields_metric = null, $apiKey = null)
    {
        return $this->getMetricsForCustomMetricAsyncWithHttpInfo($id, $fields_metric, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

    /**
     * Operation getMetricsForCustomMetricAsyncWithHttpInfo
     *
     * Get Metrics for Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_metric 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 getMetricsForCustomMetricAsyncWithHttpInfo($id, $fields_metric = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getMetricsForCustomMetricRequest($id, $fields_metric, $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 `getMetricsForCustomMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getMetricsForCustomMetricAsyncWithHttpInfo` instead
     */
    public function getCustomMetricMetricsAsyncWithHttpInfo(...$args) {
        return $this->getMetricsForCustomMetricAsyncWithHttpInfo(...$args);
    }

    /**
     * Create request for operation 'getMetricsForCustomMetric'
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  string[] $fields_metric 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 getMetricsForCustomMetricRequest($id, $fields_metric = 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 getMetricsForCustomMetric'
            );
        }

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric,
            'fields[metric]', // 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 `getMetricsForCustomMetricRequest`
     *
     * @deprecated use `getMetricsForCustomMetricRequest` instead
     */
    public function getCustomMetricMetricsRequest(...$args) {
        return $this->getMetricsForCustomMetricRequest(...$args);
    }

    /**
     * Operation getPropertiesForMetric
     *
     * Get Properties for Metric
     *
     * @param  string $id The ID of the metric (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property 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 getPropertiesForMetric($id, $additional_fields_metric_property = null, $fields_metric_property = null, $apiKey = null)
    {
        list($response) = $this->getPropertiesForMetricWithHttpInfo($id, $additional_fields_metric_property, $fields_metric_property, $apiKey);
        return $response;
    }

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

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

    /**
     * Operation getPropertiesForMetricWithHttpInfo
     *
     * Get Properties for Metric
     *
     * @param  string $id The ID of the metric (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property 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 getPropertiesForMetricWithHttpInfo($id, $additional_fields_metric_property = null, $fields_metric_property = null, $apiKey = null)
    {
        $request = $this->getPropertiesForMetricRequest($id, $additional_fields_metric_property, $fields_metric_property, $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 `getPropertiesForMetricWithHttpInfo`
     *
     * @deprecated use `getPropertiesForMetricWithHttpInfo` instead
     */
    public function getMetricMetricPropertiesWithHttpInfo(...$args) {
        return $this->getPropertiesForMetricWithHttpInfo(...$args);
    }

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

    /**
     * Operation getPropertiesForMetricAsync
     *
     * Get Properties for Metric
     *
     * @param  string $id The ID of the metric (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property 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 getPropertiesForMetricAsync($id, $additional_fields_metric_property = null, $fields_metric_property = null, $apiKey = null)
    {
        return $this->getPropertiesForMetricAsyncWithHttpInfo($id, $additional_fields_metric_property, $fields_metric_property, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

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

    /**
     * Operation getPropertiesForMetricAsyncWithHttpInfo
     *
     * Get Properties for Metric
     *
     * @param  string $id The ID of the metric (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property 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 getPropertiesForMetricAsyncWithHttpInfo($id, $additional_fields_metric_property = null, $fields_metric_property = null, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getPropertiesForMetricRequest($id, $additional_fields_metric_property, $fields_metric_property, $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 `getPropertiesForMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getPropertiesForMetricAsyncWithHttpInfo` instead
     */
    public function getMetricMetricPropertiesAsyncWithHttpInfo(...$args) {
        return $this->getPropertiesForMetricAsyncWithHttpInfo(...$args);
    }

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

    /**
     * Create request for operation 'getPropertiesForMetric'
     *
     * @param  string $id The ID of the metric (required)
     * @param  string[] $additional_fields_metric_property Request additional fields not included by default in the response. Supported values: &#39;sample_values&#39; (optional)
     * @param  string[] $fields_metric_property 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 getPropertiesForMetricRequest($id, $additional_fields_metric_property = null, $fields_metric_property = 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 getPropertiesForMetric'
            );
        }

        $resourcePath = '/api/metrics/{id}/metric-properties';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $additional_fields_metric_property,
            'additional-fields[metric-property]', // param base name
            'array', // openApiType
            'form', // style
            false, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fields_metric_property,
            'fields[metric-property]', // 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 `getPropertiesForMetricRequest`
     *
     * @deprecated use `getPropertiesForMetricRequest` instead
     */
    public function getMetricMetricPropertiesRequest(...$args) {
        return $this->getPropertiesForMetricRequest(...$args);
    }

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

    /**
     * Operation getPropertyIdsForMetric
     *
     * Get Property IDs for Metric
     *
     * @param  string $id The ID of the metric (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function getPropertyIdsForMetric($id, $apiKey = null)
    {
        list($response) = $this->getPropertyIdsForMetricWithHttpInfo($id, $apiKey);
        return $response;
    }

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

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

    /**
     * Operation getPropertyIdsForMetricWithHttpInfo
     *
     * Get Property IDs for Metric
     *
     * @param  string $id The ID of the metric (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 getPropertyIdsForMetricWithHttpInfo($id, $apiKey = null)
    {
        $request = $this->getPropertyIdsForMetricRequest($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 `getPropertyIdsForMetricWithHttpInfo`
     *
     * @deprecated use `getPropertyIdsForMetricWithHttpInfo` instead
     */
    public function getMetricRelationshipsMetricPropertiesWithHttpInfo(...$args) {
        return $this->getPropertyIdsForMetricWithHttpInfo(...$args);
    }

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

    /**
     * Operation getPropertyIdsForMetricAsync
     *
     * Get Property IDs for Metric
     *
     * @param  string $id The ID of the metric (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getPropertyIdsForMetricAsync($id, $apiKey = null)
    {
        return $this->getPropertyIdsForMetricAsyncWithHttpInfo($id, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

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

    /**
     * Operation getPropertyIdsForMetricAsyncWithHttpInfo
     *
     * Get Property IDs for Metric
     *
     * @param  string $id The ID of the metric (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getPropertyIdsForMetricAsyncWithHttpInfo($id, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->getPropertyIdsForMetricRequest($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 `getPropertyIdsForMetricAsyncWithHttpInfo`
     *
     * @deprecated use `getPropertyIdsForMetricAsyncWithHttpInfo` instead
     */
    public function getMetricRelationshipsMetricPropertiesAsyncWithHttpInfo(...$args) {
        return $this->getPropertyIdsForMetricAsyncWithHttpInfo(...$args);
    }

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

    /**
     * Create request for operation 'getPropertyIdsForMetric'
     *
     * @param  string $id The ID of the metric (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function getPropertyIdsForMetricRequest($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 getPropertyIdsForMetric'
            );
        }

        $resourcePath = '/api/metrics/{id}/relationships/metric-properties';
        $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 `getPropertyIdsForMetricRequest`
     *
     * @deprecated use `getPropertyIdsForMetricRequest` instead
     */
    public function getMetricRelationshipsMetricPropertiesRequest(...$args) {
        return $this->getPropertyIdsForMetricRequest(...$args);
    }

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

    /**
     * Operation queryMetricAggregates
     *
     * Query Metric Aggregates
     *
     * @param  \KlaviyoAPI\Model\MetricAggregateQuery $metric_aggregate_query Retrieve Metric Aggregations (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function queryMetricAggregates($metric_aggregate_query, $apiKey = null)
    {
        list($response) = $this->queryMetricAggregatesWithHttpInfo($metric_aggregate_query, $apiKey);
        return $response;
    }

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

    /**
     * Operation queryMetricAggregatesWithHttpInfo
     *
     * Query Metric Aggregates
     *
     * @param  \KlaviyoAPI\Model\MetricAggregateQuery $metric_aggregate_query Retrieve Metric Aggregations (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 queryMetricAggregatesWithHttpInfo($metric_aggregate_query, $apiKey = null)
    {
        $request = $this->queryMetricAggregatesRequest($metric_aggregate_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;
        }
    }

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

    /**
     * Operation queryMetricAggregatesAsync
     *
     * Query Metric Aggregates
     *
     * @param  \KlaviyoAPI\Model\MetricAggregateQuery $metric_aggregate_query Retrieve Metric Aggregations (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function queryMetricAggregatesAsync($metric_aggregate_query, $apiKey = null)
    {
        return $this->queryMetricAggregatesAsyncWithHttpInfo($metric_aggregate_query, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

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

    /**
     * Operation queryMetricAggregatesAsyncWithHttpInfo
     *
     * Query Metric Aggregates
     *
     * @param  \KlaviyoAPI\Model\MetricAggregateQuery $metric_aggregate_query Retrieve Metric Aggregations (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function queryMetricAggregatesAsyncWithHttpInfo($metric_aggregate_query, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->queryMetricAggregatesRequest($metric_aggregate_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 `queryMetricAggregatesAsyncWithHttpInfo`
     *
     * @deprecated use `queryMetricAggregatesAsyncWithHttpInfo` instead
     */
    public function createMetricAggregateAsyncWithHttpInfo(...$args) {
        return $this->queryMetricAggregatesAsyncWithHttpInfo(...$args);
    }

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

        $resourcePath = '/api/metric-aggregates';
        $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($metric_aggregate_query)) {
            if ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($metric_aggregate_query));
            } else {
                $httpBody = $metric_aggregate_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 `queryMetricAggregatesRequest`
     *
     * @deprecated use `queryMetricAggregatesRequest` instead
     */
    public function createMetricAggregateRequest(...$args) {
        return $this->queryMetricAggregatesRequest(...$args);
    }

    /**
     * Operation updateCustomMetric
     *
     * Update Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  \KlaviyoAPI\Model\CustomMetricPartialUpdateQuery $custom_metric_partial_update_query Update a custom metric by ID. (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function updateCustomMetric($id, $custom_metric_partial_update_query, $apiKey = null)
    {
        list($response) = $this->updateCustomMetricWithHttpInfo($id, $custom_metric_partial_update_query, $apiKey);
        return $response;
    }

    /**
     * Operation updateCustomMetricWithHttpInfo
     *
     * Update Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  \KlaviyoAPI\Model\CustomMetricPartialUpdateQuery $custom_metric_partial_update_query Update a custom metric by ID. (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 updateCustomMetricWithHttpInfo($id, $custom_metric_partial_update_query, $apiKey = null)
    {
        $request = $this->updateCustomMetricRequest($id, $custom_metric_partial_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 updateCustomMetricAsync
     *
     * Update Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  \KlaviyoAPI\Model\CustomMetricPartialUpdateQuery $custom_metric_partial_update_query Update a custom metric by ID. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCustomMetricAsync($id, $custom_metric_partial_update_query, $apiKey = null)
    {
        return $this->updateCustomMetricAsyncWithHttpInfo($id, $custom_metric_partial_update_query, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateCustomMetricAsyncWithHttpInfo
     *
     * Update Custom Metric
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  \KlaviyoAPI\Model\CustomMetricPartialUpdateQuery $custom_metric_partial_update_query Update a custom metric by ID. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCustomMetricAsyncWithHttpInfo($id, $custom_metric_partial_update_query, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->updateCustomMetricRequest($id, $custom_metric_partial_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 'updateCustomMetric'
     *
     * @param  string $id The ID of the custom metric (required)
     * @param  \KlaviyoAPI\Model\CustomMetricPartialUpdateQuery $custom_metric_partial_update_query Update a custom metric by ID. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updateCustomMetricRequest($id, $custom_metric_partial_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 updateCustomMetric'
            );
        }
        // verify the required parameter 'custom_metric_partial_update_query' is set
        if ($custom_metric_partial_update_query === null || (is_array($custom_metric_partial_update_query) && count($custom_metric_partial_update_query) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $custom_metric_partial_update_query when calling updateCustomMetric'
            );
        }

        $resourcePath = '/api/custom-metrics/{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($custom_metric_partial_update_query)) {
            if ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($custom_metric_partial_update_query));
            } else {
                $httpBody = $custom_metric_partial_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 updateMappedMetric
     *
     * Update Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  \KlaviyoAPI\Model\MappedMetricPartialUpdateQuery $mapped_metric_partial_update_query Update a mapped metric by ID (required)
     *
     * @throws \KlaviyoAPI\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array<string,mixed>|\KlaviyoAPI\Model\GetAccounts400Response|\KlaviyoAPI\Model\GetAccounts400Response
     */
    public function updateMappedMetric($id, $mapped_metric_partial_update_query, $apiKey = null)
    {
        list($response) = $this->updateMappedMetricWithHttpInfo($id, $mapped_metric_partial_update_query, $apiKey);
        return $response;
    }

    /**
     * Operation updateMappedMetricWithHttpInfo
     *
     * Update Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  \KlaviyoAPI\Model\MappedMetricPartialUpdateQuery $mapped_metric_partial_update_query Update a mapped metric by ID (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 updateMappedMetricWithHttpInfo($id, $mapped_metric_partial_update_query, $apiKey = null)
    {
        $request = $this->updateMappedMetricRequest($id, $mapped_metric_partial_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 updateMappedMetricAsync
     *
     * Update Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  \KlaviyoAPI\Model\MappedMetricPartialUpdateQuery $mapped_metric_partial_update_query Update a mapped metric by ID (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateMappedMetricAsync($id, $mapped_metric_partial_update_query, $apiKey = null)
    {
        return $this->updateMappedMetricAsyncWithHttpInfo($id, $mapped_metric_partial_update_query, $apiKey)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateMappedMetricAsyncWithHttpInfo
     *
     * Update Mapped Metric
     *
     * @param  string $id The type of mapping. (required)
     * @param  \KlaviyoAPI\Model\MappedMetricPartialUpdateQuery $mapped_metric_partial_update_query Update a mapped metric by ID (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateMappedMetricAsyncWithHttpInfo($id, $mapped_metric_partial_update_query, $apiKey = null)
    {
        $returnType = 'array<string,mixed>';
        $request = $this->updateMappedMetricRequest($id, $mapped_metric_partial_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 'updateMappedMetric'
     *
     * @param  string $id The type of mapping. (required)
     * @param  \KlaviyoAPI\Model\MappedMetricPartialUpdateQuery $mapped_metric_partial_update_query Update a mapped metric by ID (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    public function updateMappedMetricRequest($id, $mapped_metric_partial_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 updateMappedMetric'
            );
        }
        // verify the required parameter 'mapped_metric_partial_update_query' is set
        if ($mapped_metric_partial_update_query === null || (is_array($mapped_metric_partial_update_query) && count($mapped_metric_partial_update_query) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $mapped_metric_partial_update_query when calling updateMappedMetric'
            );
        }

        $resourcePath = '/api/mapped-metrics/{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($mapped_metric_partial_update_query)) {
            if ($headers['Content-Type'] === 'application/json' || $headers['Content-Type'] === 'application/vnd.api+json') {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($mapped_metric_partial_update_query));
            } else {
                $httpBody = $mapped_metric_partial_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;
    }
}
