/*
 * Copyright Elasticsearch B.V. and contributors
 * SPDX-License-Identifier: Apache-2.0
 */

// This file was automatically generated by elastic/elastic-client-generator-js
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
// and elastic/elastic-client-generator-js to regenerate this file again.

import {
  Transport,
  TransportRequestMetadata,
  TransportRequestOptions,
  TransportRequestOptionsWithMeta,
  TransportRequestOptionsWithOutMeta,
  TransportResult
} from '@elastic/transport'
import * as T from '../types'

interface That {
  transport: Transport
}

const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = {
  get_reindex: {
    path: [
      'task_id'
    ],
    body: [],
    query: [
      'wait_for_completion',
      'timeout'
    ]
  }
}

/**
  * Get the status and progress of a specific reindex task. This API follows reindex tasks across node-shutdown relocations, so callers can keep using the original task ID throughout the lifetime of the operation. Returned task IDs and timings reflect the original task, not its relocated successor. Relocated task IDs are also supported. They are followed transparently and return the task ID and timings of the original task. When the task ID cannot be resolved, the API returns the response below with a 404 status code. This response is used whether the ID is unknown, refers to a non-reindex task, refers to a sliced child subtask, or refers to a task whose node left the cluster with no stored result (e.g. a non-graceful shutdown). ``` { "error": { "type": "resource_not_found_exception", "reason": "Reindex operation [r1A2WoRbTwKZ516z6NEs5A:36619] not found" }, "status": 404 } ```
  * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch#TODO | Elasticsearch API documentation}
  */
export default async function GetReindexApi (this: That, params: T.GetReindexRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.GetReindexResponse>
export default async function GetReindexApi (this: That, params: T.GetReindexRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.GetReindexResponse, unknown>>
export default async function GetReindexApi (this: That, params: T.GetReindexRequest, options?: TransportRequestOptions): Promise<T.GetReindexResponse>
export default async function GetReindexApi (this: That, params: T.GetReindexRequest, options?: TransportRequestOptions): Promise<any> {
  const {
    path: acceptedPath
  } = acceptedParams.get_reindex

  const userQuery = params?.querystring
  const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {}

  let body: Record<string, any> | string | undefined
  const userBody = params?.body
  if (userBody != null) {
    if (typeof userBody === 'string') {
      body = userBody
    } else {
      body = { ...userBody }
    }
  }

  for (const key in params) {
    if (acceptedPath.includes(key)) {
      continue
    } else if (key !== 'body' && key !== 'querystring') {
      // @ts-expect-error
      querystring[key] = params[key]
    }
  }

  const method = 'GET'
  const path = `/_reindex/${encodeURIComponent(params.task_id.toString())}`
  const meta: TransportRequestMetadata = {
    name: 'get_reindex',
    pathParts: {
      task_id: params.task_id
    },
    acceptedParams: {
      path: ['task_id'],
      body: [],
      query: ['wait_for_completion', 'timeout']
    }
  }
  return await this.transport.request({ path, method, querystring, body, meta }, options)
}
