# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
# This code was automatically generated from the Elasticsearch Specification
# See https://github.com/elastic/elasticsearch-specification
# See Elasticsearch::ES_SPECIFICATION_COMMIT for commit hash.
module Elasticsearch
  module API
    module AsyncSearch
      module Actions
        # Get async search results.
        # Retrieve the results of a previously submitted asynchronous search request.
        # If the Elasticsearch security features are enabled, access to the results of a specific async search is restricted to the user or API key that submitted it.
        #
        # @option arguments [String] :id A unique identifier for the async search. (*Required*)
        # @option arguments [Time] :keep_alive The length of time that the async search should be available in the cluster.
        #  When not specified, the `keep_alive` set with the corresponding submit async request will be used.
        #  Otherwise, it is possible to override the value and extend the validity of the request.
        #  When this period expires, the search, if still running, is cancelled.
        #  If the search is completed, its saved results are deleted.
        # @option arguments [Boolean] :typed_keys Specify whether aggregation and suggester names should be prefixed by their respective types in the response
        # @option arguments [Time] :wait_for_completion_timeout Specifies to wait for the search to be completed up until the provided timeout.
        #  Final results will be returned if available before the timeout expires, otherwise the currently available results will be returned once the timeout expires.
        #  By default no timeout is set meaning that the currently available results will be returned without any additional wait.
        # @option arguments [Boolean] :return_intermediate_results Specifies whether the response should contain intermediate results if the query is still running when the wait_for_completion_timeout
        #  expires or if no wait_for_completion_timeout is specified.
        #  If true and the search is still running, the search response
        #  will include any hits and partial aggregations that are available.
        #  If false and the search is still running, the search response will not include any hits (but possibly include
        #  total hits) nor will include any partial aggregations.
        #  When not specified, the intermediate results are returned for running queries.
        # @option arguments [Boolean] :error_trace When set to `true` Elasticsearch will include the full stack trace of errors
        #  when they occur.
        # @option arguments [String, Array<String>] :filter_path Comma-separated list of filters in dot notation which reduce the response
        #  returned by Elasticsearch.
        # @option arguments [Boolean] :human When set to `true` will return statistics in a format suitable for humans.
        #  For example `"exists_time": "1h"` for humans and
        #  `"exists_time_in_millis": 3600000` for computers. When disabled the human
        #  readable values will be omitted. This makes sense for responses being consumed
        #  only by machines.
        # @option arguments [Boolean] :pretty If set to `true` the returned JSON will be "pretty-formatted". Only use
        #  this option for debugging only.
        # @option arguments [Hash] :headers Custom HTTP headers
        #
        # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-async-search-submit
        #
        def get(arguments = {})
          request_opts = { endpoint: arguments[:endpoint] || 'async_search.get' }

          defined_params = [:id].each_with_object({}) do |variable, set_variables|
            set_variables[variable] = arguments[variable] if arguments.key?(variable)
          end
          request_opts[:defined_params] = defined_params unless defined_params.empty?

          raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

          arguments = arguments.clone
          headers = arguments.delete(:headers) || {}

          body = nil

          _id = arguments.delete(:id)

          method = Elasticsearch::API::HTTP_GET
          path   = "_async_search/#{Utils.listify(_id)}"
          params = Utils.process_params(arguments)

          Elasticsearch::API::Response.new(
            perform_request(method, path, params, body, headers, request_opts)
          )
        end
      end
    end
  end
end
