/*
 * 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[] }> = {
  list_reindex: {
    path: [],
    body: [],
    query: [
      'detailed'
    ]
  }
}

/**
  * Get information about all currently running reindex tasks. Reindex tasks that are mid-relocation between nodes are reported once, under their original task ID, so callers do not see duplicates across the relocation chain. If the API returns a HTTP status of `200 OK`, but `node_failures` or `task_failures` are non-empty in the body, the listing is not a complete authoritative listing and may be missing tasks.
  * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch#TODO | Elasticsearch API documentation}
  */
export default async function ListReindexApi (this: That, params?: T.ListReindexRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.ListReindexResponse>
export default async function ListReindexApi (this: That, params?: T.ListReindexRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ListReindexResponse, unknown>>
export default async function ListReindexApi (this: That, params?: T.ListReindexRequest, options?: TransportRequestOptions): Promise<T.ListReindexResponse>
export default async function ListReindexApi (this: That, params?: T.ListReindexRequest, options?: TransportRequestOptions): Promise<any> {
  const {
    path: acceptedPath
  } = acceptedParams.list_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 }
    }
  }

  params = params ?? {}
  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'
  const meta: TransportRequestMetadata = {
    name: 'list_reindex',
    acceptedParams: {
      path: [],
      body: [],
      query: ['detailed']
    }
  }
  return await this.transport.request({ path, method, querystring, body, meta }, options)
}
