<?php

declare(strict_types=1);

/**
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 *
 * OpenSearch PHP client
 *
 * @link      https://github.com/opensearch-project/opensearch-php/
 * @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
 * @license   http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
 * @license   https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1
 *
 * Licensed to Elasticsearch B.V under one or more agreements.
 * Elasticsearch B.V licenses this file to you under the Apache 2.0 License or
 * the GNU Lesser General Public License, Version 2.1, at your option.
 * See the LICENSE file in the project root for more information.
 */

namespace OpenSearch\Namespaces;

use OpenSearch\Endpoints\Nodes\HotThreads;
use OpenSearch\Endpoints\Nodes\Info;
use OpenSearch\Endpoints\Nodes\ReloadSecureSettings;
use OpenSearch\Endpoints\Nodes\Stats;
use OpenSearch\Endpoints\Nodes\Usage;

/**
 * Class NodesNamespace
 *
 * NOTE: This file is autogenerated using util/GenerateEndpoints.php
 */
class NodesNamespace extends AbstractNamespace
{
    /**
     * Returns information about hot threads on each node in the cluster.
     *
     * @param array{node_id?: mixed, ignore_idle_threads?: bool, interval?: string, snapshots?: int, threads?: int, timeout?: string, type?: string, pretty?: bool, human?: bool, error_trace?: bool, source?: string, filter_path?: mixed} $params
     * - node_id: A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes.
     * - ignore_idle_threads: Whether to show threads that are in known-idle places, such as waiting on a socket select or pulling from an empty task queue. (Default: true)
     * - interval: The time interval between thread stack trace samples.
     * - snapshots: The number of thread stack trace samples to collect. (Default: 10)
     * - threads: The number of threads to provide information for. (Default: 3)
     * - timeout: The amount of time to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.
     * - type: The type to sample.
     * - pretty: Whether to pretty-format the returned JSON response. (Default: false)
     * - human: Whether to return human-readable values for statistics. (Default: false)
     * - error_trace: Whether to include the stack trace of returned errors. (Default: false)
     * - source: The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
     * - filter_path: A comma-separated list of filters used to filter the response. Use wildcards to match any field or part of a field's name. To exclude fields, use `-`.
     * @return array
     */
    public function hotThreads(array $params = [])
    {
        $node_id = $this->extractArgument($params, 'node_id');

        $endpoint = $this->endpointFactory->getEndpoint(HotThreads::class);
        $endpoint->setParams($params);
        $endpoint->setNodeId($node_id);

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

    /**
     * Returns information about nodes in the cluster.
     *
     * @param array{node_id_or_metric?: mixed, metric?: mixed, node_id?: mixed, flat_settings?: bool, timeout?: string, pretty?: bool, human?: bool, error_trace?: bool, source?: string, filter_path?: mixed} $params
     * - node_id_or_metric: Limits the information returned to a list of node IDs or specific metrics. Supports a comma-separated list, such as `node1,node2` or `http,ingest`.
     * - metric: Limits the information returned to the specific metrics. Supports a comma-separated list, such as http,ingest.
     * - node_id: Comma-separated list of node IDs or names used to limit returned information.
     * - flat_settings: When `true`, returns settings in flat format. (Default: false)
     * - timeout: The amount of time to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.
     * - pretty: Whether to pretty-format the returned JSON response. (Default: false)
     * - human: Whether to return human-readable values for statistics. (Default: false)
     * - error_trace: Whether to include the stack trace of returned errors. (Default: false)
     * - source: The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
     * - filter_path: A comma-separated list of filters used to filter the response. Use wildcards to match any field or part of a field's name. To exclude fields, use `-`.
     * @return array
     */
    public function info(array $params = [])
    {
        $node_id_or_metric = $this->extractArgument($params, 'node_id_or_metric');
        $metric = $this->extractArgument($params, 'metric');
        $node_id = $this->extractArgument($params, 'node_id');

        $endpoint = $this->endpointFactory->getEndpoint(Info::class);
        $endpoint->setParams($params);
        $endpoint->setNodeIdOrMetric($node_id_or_metric);
        $endpoint->setMetric($metric);
        $endpoint->setNodeId($node_id);

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

    /**
     * Reloads secure settings.
     *
     * @param array{node_id?: mixed, timeout?: string, pretty?: bool, human?: bool, error_trace?: bool, source?: string, filter_path?: mixed, body?: mixed} $params
     * - node_id: The names of particular nodes in the cluster to target.
     * - timeout: The amount of time to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.
     * - pretty: Whether to pretty-format the returned JSON response. (Default: false)
     * - human: Whether to return human-readable values for statistics. (Default: false)
     * - error_trace: Whether to include the stack trace of returned errors. (Default: false)
     * - source: The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
     * - filter_path: A comma-separated list of filters used to filter the response. Use wildcards to match any field or part of a field's name. To exclude fields, use `-`.
     * - body: An object containing the password for the OpenSearch keystore.
     * @return array
     */
    public function reloadSecureSettings(array $params = [])
    {
        $node_id = $this->extractArgument($params, 'node_id');
        $body = $this->extractArgument($params, 'body');

        $endpoint = $this->endpointFactory->getEndpoint(ReloadSecureSettings::class);
        $endpoint->setParams($params);
        $endpoint->setNodeId($node_id);
        $endpoint->setBody($body);

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

    /**
     * Returns statistical information about nodes in the cluster.
     *
     * @param array{node_id?: mixed, metric?: mixed, index_metric?: mixed, completion_fields?: mixed, fielddata_fields?: mixed, fields?: mixed, groups?: mixed, include_segment_file_sizes?: bool, level?: mixed, timeout?: string, types?: mixed, pretty?: bool, human?: bool, error_trace?: bool, source?: string, filter_path?: mixed} $params
     * - node_id: A comma-separated list of node IDs or names used to limit returned information.
     * - metric: Limit the information returned to the specified metrics.
     * - index_metric: Limit the information returned for indexes metric to the specified index metrics. It can be used only if indexes (or all) metric is specified.
     * - completion_fields: A comma-separated list or wildcard expressions of fields to include in field data and suggest statistics.
     * - fielddata_fields: A comma-separated list or wildcard expressions of fields to include in field data statistics.
     * - fields: A comma-separated list or wildcard expressions of fields to include in the statistics.
     * - groups: A comma-separated list of search groups to include in the search statistics.
     * - include_segment_file_sizes: When `true`, reports the aggregated disk usage of each one of the Lucene index files (only applies if segment stats are requested). (Default: false)
     * - level: Indicates whether statistics are aggregated at the cluster, index, or shard level. (Options: cluster, indices, shards)
     * - timeout: The amount of time to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.
     * - types: A comma-separated list of document types for the indexing index metric.
     * - pretty: Whether to pretty-format the returned JSON response. (Default: false)
     * - human: Whether to return human-readable values for statistics. (Default: false)
     * - error_trace: Whether to include the stack trace of returned errors. (Default: false)
     * - source: The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
     * - filter_path: A comma-separated list of filters used to filter the response. Use wildcards to match any field or part of a field's name. To exclude fields, use `-`.
     * @return array
     */
    public function stats(array $params = [])
    {
        $node_id = $this->extractArgument($params, 'node_id');
        $metric = $this->extractArgument($params, 'metric');
        $index_metric = $this->extractArgument($params, 'index_metric');

        $endpoint = $this->endpointFactory->getEndpoint(Stats::class);
        $endpoint->setParams($params);
        $endpoint->setNodeId($node_id);
        $endpoint->setMetric($metric);
        $endpoint->setIndexMetric($index_metric);

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

    /**
     * Returns low-level information about REST actions usage on nodes.
     *
     * @param array{node_id?: mixed, metric?: mixed, timeout?: string, pretty?: bool, human?: bool, error_trace?: bool, source?: string, filter_path?: mixed} $params
     * - node_id: A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes
     * - metric: Limits the information returned to the specific metrics. A comma-separated list of the following options: `_all`, `rest_actions`.
     * - timeout: Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.
     * - pretty: Whether to pretty-format the returned JSON response. (Default: false)
     * - human: Whether to return human-readable values for statistics. (Default: false)
     * - error_trace: Whether to include the stack trace of returned errors. (Default: false)
     * - source: The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
     * - filter_path: A comma-separated list of filters used to filter the response. Use wildcards to match any field or part of a field's name. To exclude fields, use `-`.
     * @return array
     */
    public function usage(array $params = [])
    {
        $node_id = $this->extractArgument($params, 'node_id');
        $metric = $this->extractArgument($params, 'metric');

        $endpoint = $this->endpointFactory->getEndpoint(Usage::class);
        $endpoint->setParams($params);
        $endpoint->setNodeId($node_id);
        $endpoint->setMetric($metric);

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

}
