<?php

// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.

namespace Algolia\AlgoliaSearch\Configuration;

class SearchConfig extends Configuration
{
    protected $clientName = 'Search';

    private $defaultWaitTaskTimeBeforeRetry = 5000; // 5 sec in milliseconds
    private $defaultMaxRetries = 100;

    public static function create($appId, $apiKey)
    {
        $config = [
            'appId' => $appId,
            'apiKey' => $apiKey,
        ];

        return new static($config);
    }

    public function setWaitTaskTimeBeforeRetry($waitTaskTimeBeforeRetry)
    {
        $this->config['waitTaskTimeBeforeRetry'] = $waitTaskTimeBeforeRetry;

        return $this;
    }

    public function getWaitTaskTimeBeforeRetry()
    {
        return $this->config['waitTaskTimeBeforeRetry'];
    }

    /**
     * Sets the max retries value used in the Search helpers (e.g. replaceAllobjects).
     *
     * @param number $maxRetries the user agent of the api client
     *
     * @return $this
     */
    public function setMaxRetries($maxRetries)
    {
        $this->config['defaultMaxRetries'] = $maxRetries;

        return $this;
    }

    public function getDefaultMaxRetries()
    {
        return $this->config['defaultMaxRetries'];
    }

    /**
     * Sets the `TransformationOptions` used by the `*WithTransformation` helpers.
     *
     * Read by `SearchClient::createWithConfig` to build the ingestion transporter; only the
     * fields set on `TransformationOptions` override the Ingestion API defaults (25s timeouts,
     * region-derived hosts) — the parent `SearchConfig` is never forwarded.
     *
     * To replace the transporter on an existing client, use `SearchClient::setTransformationOptions`.
     *
     * @see https://www.algolia.com/doc/libraries/sdk/methods/ingestion/
     *
     * @return $this
     */
    public function setTransformationOptions(TransformationOptions $transformationOptions)
    {
        $this->config['transformationOptions'] = $transformationOptions;
        // Mirror the region into the legacy slot so `getTransformationRegion()` stays consistent.
        $this->config['region'] = $transformationOptions->getRegion();

        return $this;
    }

    /**
     * @return null|TransformationOptions
     */
    public function getTransformationOptions()
    {
        return $this->config['transformationOptions'];
    }

    /**
     * Sets the region used by the transformation pipeline (via the `*WithTransformation` methods).
     *
     * @deprecated The old setter forwarded the parent `SearchConfig` (hosts, timeouts, headers,
     *             compression) to the ingestion transporter, letting search settings bleed into
     *             ingestion calls. Use {@see SearchConfig::setTransformationOptions()} instead — it
     *             defaults to the Ingestion API defaults (25s timeouts, region-derived hosts, no
     *             compression) and only overrides fields explicitly set on `TransformationOptions`.
     * @see https://www.algolia.com/doc/libraries/sdk/methods/ingestion/
     *
     * @param string $region the Algolia region for the Ingestion API (`"us"` or `"eu"`)
     *
     * @return $this
     */
    public function setTransformationRegion($region)
    {
        $this->config['region'] = $region;
        $this->config['transformationOptions'] = (null === $region || '' === $region)
            ? null
            : new TransformationOptions($region);

        return $this;
    }

    public function getTransformationRegion()
    {
        return $this->config['region'];
    }

    public function getDefaultConfiguration()
    {
        return [
            'appId' => '',
            'apiKey' => '',
            'hosts' => null,
            'hasFullHosts' => false,
            'readTimeout' => 5,
            'writeTimeout' => 30,
            'connectTimeout' => 2,
            'defaultHeaders' => [],
            'region' => null,
            'transformationOptions' => null,
            'waitTaskTimeBeforeRetry' => $this->defaultWaitTaskTimeBeforeRetry,
            'defaultMaxRetries' => $this->defaultMaxRetries,
            'defaultForwardToReplicas' => null,
            'batchSize' => 1000,
        ];
    }
}
