<?php

declare(strict_types=1);

/**
 * SPDX-License-Identifier: Apache-2.0
 *
 * The OpenSearch Contributors require contributions made to
 * this file be licensed under the Apache-2.0 license or a
 * compatible open source license.
 *
 * Modifications Copyright OpenSearch Contributors. See
 * GitHub history for details.
 */

namespace OpenSearch\Namespaces;

use OpenSearch\Namespaces\AbstractNamespace;

/**
 * Class SqlNamespace
 *
 * NOTE: This file is autogenerated using util/GenerateEndpoints.php
 */
class SqlNamespace extends AbstractNamespace
{
    /**
     * Clear the cursor context.
     *
     * $params['format']      = (string) A short version of the Accept header, e.g. json, yaml.
     * $params['sanitize']    = (boolean) Specifies whether to escape special characters in the results (Default = true)
     * $params['pretty']      = (boolean) Whether to pretty format the returned JSON response.
     * $params['human']       = (boolean) Whether to return human readable values for statistics.
     * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
     * $params['source']      = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
     * $params['filter_path'] = (any) Comma-separated list of filters used to reduce the response.
     *
     * @param array $params Associative array of parameters
     * @return array
     */
    public function close(array $params = [])
    {
        $body = $this->extractArgument($params, 'body');

        $endpointBuilder = $this->endpoints;
        $endpoint = $endpointBuilder('Sql\Close');
        $endpoint->setParams($params);
        $endpoint->setBody($body);

        return $this->performRequest($endpoint);
    }
    /**
     * Collect metrics for the plugin within the interval.
     *
     * $params['format']      = (string) A short version of the Accept header, e.g. json, yaml.
     * $params['sanitize']    = (boolean) Specifies whether to escape special characters in the results (Default = true)
     * $params['pretty']      = (boolean) Whether to pretty format the returned JSON response.
     * $params['human']       = (boolean) Whether to return human readable values for statistics.
     * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
     * $params['source']      = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
     * $params['filter_path'] = (any) Comma-separated list of filters used to reduce the response.
     *
     * @param array $params Associative array of parameters
     * @return array
     */
    public function getStats(array $params = [])
    {
        $endpointBuilder = $this->endpoints;
        $endpoint = $endpointBuilder('Sql\GetStats');
        $endpoint->setParams($params);

        return $this->performRequest($endpoint);
    }
    /**
     * By a stats endpoint, you are able to collect metrics for the plugin within the interval.
     *
     * $params['format']      = (string) A short version of the Accept header, e.g. json, yaml.
     * $params['sanitize']    = (boolean) Specifies whether to escape special characters in the results (Default = true)
     * $params['pretty']      = (boolean) Whether to pretty format the returned JSON response.
     * $params['human']       = (boolean) Whether to return human readable values for statistics.
     * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
     * $params['source']      = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
     * $params['filter_path'] = (any) Comma-separated list of filters used to reduce the response.
     *
     * @param array $params Associative array of parameters
     * @return array
     */
    public function postStats(array $params = [])
    {
        $body = $this->extractArgument($params, 'body');

        $endpointBuilder = $this->endpoints;
        $endpoint = $endpointBuilder('Sql\PostStats');
        $endpoint->setParams($params);
        $endpoint->setBody($body);

        return $this->performRequest($endpoint);
    }
    /**
     * Adds SQL settings to the standard OpenSearch cluster settings.
     *
     * $params['format']      = (string) A short version of the Accept header, e.g. json, yaml.
     * $params['pretty']      = (boolean) Whether to pretty format the returned JSON response.
     * $params['human']       = (boolean) Whether to return human readable values for statistics.
     * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors.
     * $params['source']      = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
     * $params['filter_path'] = (any) Comma-separated list of filters used to reduce the response.
     *
     * @param array $params Associative array of parameters
     * @return array
     */
    public function settings(array $params = [])
    {
        $body = $this->extractArgument($params, 'body');

        $endpointBuilder = $this->endpoints;
        $endpoint = $endpointBuilder('Sql\Settings');
        $endpoint->setParams($params);
        $endpoint->setBody($body);

        return $this->performRequest($endpoint);
    }    /**
     * This API will be removed in a future version. Use 'close' API instead.
     *
     * $params['cursor'] = (string) The cursor given by the server
     *
     * @param array{'cursor': string} $params Associative array of parameters
     * @return array
     */
    public function closeCursor(array $params): array
    {
        $endpointBuilder = $this->endpoints;

        $endpoint = $endpointBuilder('Sql\Close');
        $endpoint->setBody(array_filter([
            'cursor' => $this->extractArgument($params, 'cursor'),
        ]));
        $endpoint->setParams($params);

        return $this->performRequest($endpoint);
    }    /**
     * $params['query'] = (string) The SQL Query
     *
     * @param array{'query': string} $params Associative array of parameters
     * @return array
     *
     * Note: Use of query parameter is deprecated. Pass it in `body` instead.
     */
    public function explain(array $params): array
    {
        $endpointBuilder = $this->endpoints;

        $body = $this->extractArgument($params, 'body') ?? [];
        $query = $this->extractArgument($params, 'query');

        $endpoint = $endpointBuilder('Sql\Explain');
        $endpoint->setBody(array_merge($body, [
            'query' => $query,
        ]));
        $endpoint->setParams($params);

        return $this->performRequest($endpoint);
    }    /**
     * $params['query'] = (string) The SQL Query
     * $params['format'] = (string) The response format
     * $params['cursor'] = (string) The cursor given by the server
     * $params['fetch_size'] = (int) The fetch size
     *
     * @param array{'query'?: string, 'cursor'?: string, 'fetch_size'?: int} $params Associative array of parameters
     * @return array
     *
     * Note: Use of `query`, `cursor` and `fetch_size` parameters is deprecated. Pass them in `body` instead.
     *
     */
    public function query(array $params): array
    {
        $endpointBuilder = $this->endpoints;

        $endpoint = $endpointBuilder('Sql\Query');
        $body = $this->extractArgument($params, 'body') ?? [];
        $endpoint->setBody(array_merge($body, array_filter([
            'query' => $this->extractArgument($params, 'query'),
            'cursor' => $this->extractArgument($params, 'cursor'),
            'fetch_size' => $this->extractArgument($params, 'fetch_size'),
        ])));
        $endpoint->setParams($params);

        return $this->performRequest($endpoint);
    }
}
