/*
 * 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'
import { kAcceptedParams } from '../../symbols'

interface That {
  transport: Transport
  [kAcceptedParams]: Record<string, { path: string[], body: string[], query: string[] }>
}

const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty']

export default class Esql {
  transport: Transport
  [kAcceptedParams]: Record<string, { path: string[], body: string[], query: string[] }>
  constructor (transport: Transport) {
    this.transport = transport
    this[kAcceptedParams] = {
      'esql.async_query': {
        path: [],
        body: [
          'columnar',
          'filter',
          'time_zone',
          'locale',
          'params',
          'profile',
          'query',
          'tables',
          'include_ccs_metadata',
          'include_execution_metadata',
          'wait_for_completion_timeout',
          'keep_alive',
          'keep_on_completion',
          'project_routing',
          'settings'
        ],
        query: [
          'allow_partial_results',
          'delimiter',
          'drop_null_columns',
          'format'
        ]
      },
      'esql.async_query_delete': {
        path: [
          'id'
        ],
        body: [],
        query: []
      },
      'esql.async_query_get': {
        path: [
          'id'
        ],
        body: [],
        query: [
          'drop_null_columns',
          'format',
          'keep_alive',
          'wait_for_completion_timeout'
        ]
      },
      'esql.async_query_stop': {
        path: [
          'id'
        ],
        body: [],
        query: [
          'drop_null_columns'
        ]
      },
      'esql.delete_data_source': {
        path: [
          'name'
        ],
        body: [],
        query: [
          'master_timeout',
          'timeout'
        ]
      },
      'esql.delete_dataset': {
        path: [
          'name'
        ],
        body: [],
        query: [
          'master_timeout',
          'timeout'
        ]
      },
      'esql.delete_view': {
        path: [
          'name'
        ],
        body: [],
        query: []
      },
      'esql.get_data_source': {
        path: [
          'name'
        ],
        body: [],
        query: [
          'master_timeout'
        ]
      },
      'esql.get_dataset': {
        path: [
          'name'
        ],
        body: [],
        query: [
          'master_timeout'
        ]
      },
      'esql.get_query': {
        path: [
          'id'
        ],
        body: [],
        query: []
      },
      'esql.get_view': {
        path: [
          'name'
        ],
        body: [],
        query: []
      },
      'esql.list_queries': {
        path: [],
        body: [],
        query: []
      },
      'esql.put_data_source': {
        path: [
          'name'
        ],
        body: [
          'type',
          'description',
          'settings'
        ],
        query: [
          'master_timeout',
          'timeout'
        ]
      },
      'esql.put_dataset': {
        path: [
          'name'
        ],
        body: [
          'data_source',
          'resource',
          'description',
          'mappings',
          'settings'
        ],
        query: [
          'master_timeout',
          'timeout'
        ]
      },
      'esql.put_view': {
        path: [
          'name'
        ],
        body: [
          'query'
        ],
        query: []
      },
      'esql.query': {
        path: [],
        body: [
          'columnar',
          'filter',
          'time_zone',
          'locale',
          'params',
          'profile',
          'query',
          'tables',
          'include_ccs_metadata',
          'include_execution_metadata',
          'project_routing',
          'settings'
        ],
        query: [
          'format',
          'delimiter',
          'drop_null_columns',
          'allow_partial_results'
        ]
      }
    }
  }

  /**
    * Run an async ES|QL query. Asynchronously run an ES|QL (Elasticsearch query language) query, monitor its progress, and retrieve results when they become available. The API accepts the same parameters and request body as the synchronous query API, along with additional async related properties.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-async-query | Elasticsearch API documentation}
    */
  async asyncQuery (this: That, params: T.EsqlAsyncQueryRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlAsyncQueryResponse>
  async asyncQuery (this: That, params: T.EsqlAsyncQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlAsyncQueryResponse, unknown>>
  async asyncQuery (this: That, params: T.EsqlAsyncQueryRequest, options?: TransportRequestOptions): Promise<T.EsqlAsyncQueryResponse>
  async asyncQuery (this: That, params: T.EsqlAsyncQueryRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath,
      body: acceptedBody,
      query: acceptedQuery
    } = this[kAcceptedParams]['esql.async_query']

    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 (acceptedBody.includes(key)) {
        body = body ?? {}
        // @ts-expect-error
        body[key] = params[key]
      } else if (acceptedPath.includes(key)) {
        continue
      } else if (key !== 'body' && key !== 'querystring') {
        if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) {
          // @ts-expect-error
          querystring[key] = params[key]
        } else {
          body = body ?? {}
          // @ts-expect-error
          body[key] = params[key]
        }
      }
    }

    const method = 'POST'
    const path = '/_query/async'
    const meta: TransportRequestMetadata = {
      name: 'esql.async_query',
      acceptedParams: {
        path: [],
        body: ['columnar', 'filter', 'time_zone', 'locale', 'params', 'profile', 'query', 'tables', 'include_ccs_metadata', 'include_execution_metadata', 'wait_for_completion_timeout', 'keep_alive', 'keep_on_completion', 'project_routing', 'settings'],
        query: ['allow_partial_results', 'delimiter', 'drop_null_columns', 'format']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Delete an async ES|QL query. If the query is still running, it is cancelled. Otherwise, the stored results are deleted. If the Elasticsearch security features are enabled, only the following users can use this API to delete a query: * The authenticated user that submitted the original query request * Users with the `cancel_task` cluster privilege
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-async-query-delete | Elasticsearch API documentation}
    */
  async asyncQueryDelete (this: That, params: T.EsqlAsyncQueryDeleteRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlAsyncQueryDeleteResponse>
  async asyncQueryDelete (this: That, params: T.EsqlAsyncQueryDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlAsyncQueryDeleteResponse, unknown>>
  async asyncQueryDelete (this: That, params: T.EsqlAsyncQueryDeleteRequest, options?: TransportRequestOptions): Promise<T.EsqlAsyncQueryDeleteResponse>
  async asyncQueryDelete (this: That, params: T.EsqlAsyncQueryDeleteRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.async_query_delete']

    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 = 'DELETE'
    const path = `/_query/async/${encodeURIComponent(params.id.toString())}`
    const meta: TransportRequestMetadata = {
      name: 'esql.async_query_delete',
      pathParts: {
        id: params.id
      },
      acceptedParams: {
        path: ['id'],
        body: [],
        query: []
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Get async ES|QL query results. Get the current status and available results or stored results for an ES|QL asynchronous query. If the Elasticsearch security features are enabled, only the user who first submitted the ES|QL query can retrieve the results using this API.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-async-query-get | Elasticsearch API documentation}
    */
  async asyncQueryGet (this: That, params: T.EsqlAsyncQueryGetRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlAsyncQueryGetResponse>
  async asyncQueryGet (this: That, params: T.EsqlAsyncQueryGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlAsyncQueryGetResponse, unknown>>
  async asyncQueryGet (this: That, params: T.EsqlAsyncQueryGetRequest, options?: TransportRequestOptions): Promise<T.EsqlAsyncQueryGetResponse>
  async asyncQueryGet (this: That, params: T.EsqlAsyncQueryGetRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.async_query_get']

    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 = `/_query/async/${encodeURIComponent(params.id.toString())}`
    const meta: TransportRequestMetadata = {
      name: 'esql.async_query_get',
      pathParts: {
        id: params.id
      },
      acceptedParams: {
        path: ['id'],
        body: [],
        query: ['drop_null_columns', 'format', 'keep_alive', 'wait_for_completion_timeout']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Stop async ES|QL query. This API interrupts the query execution and returns the results so far. If the Elasticsearch security features are enabled, only the user who first submitted the ES|QL query can stop it.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-async-query-stop | Elasticsearch API documentation}
    */
  async asyncQueryStop (this: That, params: T.EsqlAsyncQueryStopRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlAsyncQueryStopResponse>
  async asyncQueryStop (this: That, params: T.EsqlAsyncQueryStopRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlAsyncQueryStopResponse, unknown>>
  async asyncQueryStop (this: That, params: T.EsqlAsyncQueryStopRequest, options?: TransportRequestOptions): Promise<T.EsqlAsyncQueryStopResponse>
  async asyncQueryStop (this: That, params: T.EsqlAsyncQueryStopRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.async_query_stop']

    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 = 'POST'
    const path = `/_query/async/${encodeURIComponent(params.id.toString())}/stop`
    const meta: TransportRequestMetadata = {
      name: 'esql.async_query_stop',
      pathParts: {
        id: params.id
      },
      acceptedParams: {
        path: ['id'],
        body: [],
        query: ['drop_null_columns']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Delete ES|QL data sources. Deletes one or more data sources used in ES|QL data federation. Fails with `409` if any dataset references one of the named data sources; delete the dependent datasets first.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-delete-data-source | Elasticsearch API documentation}
    */
  async deleteDataSource (this: That, params: T.EsqlDeleteDataSourceRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlDeleteDataSourceResponse>
  async deleteDataSource (this: That, params: T.EsqlDeleteDataSourceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlDeleteDataSourceResponse, unknown>>
  async deleteDataSource (this: That, params: T.EsqlDeleteDataSourceRequest, options?: TransportRequestOptions): Promise<T.EsqlDeleteDataSourceResponse>
  async deleteDataSource (this: That, params: T.EsqlDeleteDataSourceRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.delete_data_source']

    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 = 'DELETE'
    const path = `/_query/data_source/${encodeURIComponent(params.name.toString())}`
    const meta: TransportRequestMetadata = {
      name: 'esql.delete_data_source',
      pathParts: {
        name: params.name
      },
      acceptedParams: {
        path: ['name'],
        body: [],
        query: ['master_timeout', 'timeout']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Delete ES|QL datasets. Deletes one or more datasets used in ES|QL data federation. If any specified dataset does not exist, the request fails and no datasets are deleted.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-delete-dataset | Elasticsearch API documentation}
    */
  async deleteDataset (this: That, params: T.EsqlDeleteDatasetRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlDeleteDatasetResponse>
  async deleteDataset (this: That, params: T.EsqlDeleteDatasetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlDeleteDatasetResponse, unknown>>
  async deleteDataset (this: That, params: T.EsqlDeleteDatasetRequest, options?: TransportRequestOptions): Promise<T.EsqlDeleteDatasetResponse>
  async deleteDataset (this: That, params: T.EsqlDeleteDatasetRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.delete_dataset']

    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 = 'DELETE'
    const path = `/_query/dataset/${encodeURIComponent(params.name.toString())}`
    const meta: TransportRequestMetadata = {
      name: 'esql.delete_dataset',
      pathParts: {
        name: params.name
      },
      acceptedParams: {
        path: ['name'],
        body: [],
        query: ['master_timeout', 'timeout']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Delete an ES|QL view. Deletes a stored ES|QL view.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch#TODO | Elasticsearch API documentation}
    */
  async deleteView (this: That, params: T.EsqlDeleteViewRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlDeleteViewResponse>
  async deleteView (this: That, params: T.EsqlDeleteViewRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlDeleteViewResponse, unknown>>
  async deleteView (this: That, params: T.EsqlDeleteViewRequest, options?: TransportRequestOptions): Promise<T.EsqlDeleteViewResponse>
  async deleteView (this: That, params: T.EsqlDeleteViewRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.delete_view']

    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 = 'DELETE'
    const path = `/_query/view/${encodeURIComponent(params.name.toString())}`
    const meta: TransportRequestMetadata = {
      name: 'esql.delete_view',
      pathParts: {
        name: params.name
      },
      acceptedParams: {
        path: ['name'],
        body: [],
        query: []
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Get ES|QL data sources. Returns one or more data sources used in ES|QL data federation. A concrete-name miss returns `404`; a wildcard pattern or list-all request with no match returns `200` with an empty array.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-get-data-source | Elasticsearch API documentation}
    */
  async getDataSource (this: That, params?: T.EsqlGetDataSourceRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlGetDataSourceResponse>
  async getDataSource (this: That, params?: T.EsqlGetDataSourceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlGetDataSourceResponse, unknown>>
  async getDataSource (this: That, params?: T.EsqlGetDataSourceRequest, options?: TransportRequestOptions): Promise<T.EsqlGetDataSourceResponse>
  async getDataSource (this: That, params?: T.EsqlGetDataSourceRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.get_data_source']

    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]
      }
    }

    let method = ''
    let path = ''
    if (params.name != null) {
      method = 'GET'
      path = `/_query/data_source/${encodeURIComponent(params.name.toString())}`
    } else {
      method = 'GET'
      path = '/_query/data_source'
    }
    const meta: TransportRequestMetadata = {
      name: 'esql.get_data_source',
      pathParts: {
        name: params.name
      },
      acceptedParams: {
        path: ['name'],
        body: [],
        query: ['master_timeout']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Get ES|QL datasets. Returns one or more datasets used in ES|QL data federation. A concrete-name miss returns `404`; a wildcard pattern or list-all request with no match returns `200` with an empty array.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-get-dataset | Elasticsearch API documentation}
    */
  async getDataset (this: That, params?: T.EsqlGetDatasetRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlGetDatasetResponse>
  async getDataset (this: That, params?: T.EsqlGetDatasetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlGetDatasetResponse, unknown>>
  async getDataset (this: That, params?: T.EsqlGetDatasetRequest, options?: TransportRequestOptions): Promise<T.EsqlGetDatasetResponse>
  async getDataset (this: That, params?: T.EsqlGetDatasetRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.get_dataset']

    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]
      }
    }

    let method = ''
    let path = ''
    if (params.name != null) {
      method = 'GET'
      path = `/_query/dataset/${encodeURIComponent(params.name.toString())}`
    } else {
      method = 'GET'
      path = '/_query/dataset'
    }
    const meta: TransportRequestMetadata = {
      name: 'esql.get_dataset',
      pathParts: {
        name: params.name
      },
      acceptedParams: {
        path: ['name'],
        body: [],
        query: ['master_timeout']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Get a specific running ES|QL query information. Returns an object extended information about a running ES|QL query.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-get-query | Elasticsearch API documentation}
    */
  async getQuery (this: That, params: T.EsqlGetQueryRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlGetQueryResponse>
  async getQuery (this: That, params: T.EsqlGetQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlGetQueryResponse, unknown>>
  async getQuery (this: That, params: T.EsqlGetQueryRequest, options?: TransportRequestOptions): Promise<T.EsqlGetQueryResponse>
  async getQuery (this: That, params: T.EsqlGetQueryRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.get_query']

    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 = `/_query/queries/${encodeURIComponent(params.id.toString())}`
    const meta: TransportRequestMetadata = {
      name: 'esql.get_query',
      pathParts: {
        id: params.id
      },
      acceptedParams: {
        path: ['id'],
        body: [],
        query: []
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Get an ES|QL view. Returns a stored ES|QL view.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch#TODO | Elasticsearch API documentation}
    */
  async getView (this: That, params?: T.EsqlGetViewRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlGetViewResponse>
  async getView (this: That, params?: T.EsqlGetViewRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlGetViewResponse, unknown>>
  async getView (this: That, params?: T.EsqlGetViewRequest, options?: TransportRequestOptions): Promise<T.EsqlGetViewResponse>
  async getView (this: That, params?: T.EsqlGetViewRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.get_view']

    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]
      }
    }

    let method = ''
    let path = ''
    if (params.name != null) {
      method = 'GET'
      path = `/_query/view/${encodeURIComponent(params.name.toString())}`
    } else {
      method = 'GET'
      path = '/_query/view'
    }
    const meta: TransportRequestMetadata = {
      name: 'esql.get_view',
      pathParts: {
        name: params.name
      },
      acceptedParams: {
        path: ['name'],
        body: [],
        query: []
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Get running ES|QL queries information. Returns an object containing IDs and other information about the running ES|QL queries.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-list-queries | Elasticsearch API documentation}
    */
  async listQueries (this: That, params?: T.EsqlListQueriesRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlListQueriesResponse>
  async listQueries (this: That, params?: T.EsqlListQueriesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlListQueriesResponse, unknown>>
  async listQueries (this: That, params?: T.EsqlListQueriesRequest, options?: TransportRequestOptions): Promise<T.EsqlListQueriesResponse>
  async listQueries (this: That, params?: T.EsqlListQueriesRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['esql.list_queries']

    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 = '/_query/queries'
    const meta: TransportRequestMetadata = {
      name: 'esql.list_queries',
      acceptedParams: {
        path: [],
        body: [],
        query: []
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Create or update an ES|QL data source. Creates or replaces a named, type-specific data source configuration for ES|QL data federation. Datasets reference data source configurations to access external data. Names must be lowercase and follow index or alias naming rules.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-put-data-source | Elasticsearch API documentation}
    */
  async putDataSource (this: That, params: T.EsqlPutDataSourceRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlPutDataSourceResponse>
  async putDataSource (this: That, params: T.EsqlPutDataSourceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlPutDataSourceResponse, unknown>>
  async putDataSource (this: That, params: T.EsqlPutDataSourceRequest, options?: TransportRequestOptions): Promise<T.EsqlPutDataSourceResponse>
  async putDataSource (this: That, params: T.EsqlPutDataSourceRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath,
      body: acceptedBody,
      query: acceptedQuery
    } = this[kAcceptedParams]['esql.put_data_source']

    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 (acceptedBody.includes(key)) {
        body = body ?? {}
        // @ts-expect-error
        body[key] = params[key]
      } else if (acceptedPath.includes(key)) {
        continue
      } else if (key !== 'body' && key !== 'querystring') {
        if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) {
          // @ts-expect-error
          querystring[key] = params[key]
        } else {
          body = body ?? {}
          // @ts-expect-error
          body[key] = params[key]
        }
      }
    }

    const method = 'PUT'
    const path = `/_query/data_source/${encodeURIComponent(params.name.toString())}`
    const meta: TransportRequestMetadata = {
      name: 'esql.put_data_source',
      pathParts: {
        name: params.name
      },
      acceptedParams: {
        path: ['name'],
        body: ['type', 'description', 'settings'],
        query: ['master_timeout', 'timeout']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Create or update an ES|QL dataset. Creates or replaces a dataset that references a data source in ES|QL data federation. Dataset names participate in the index namespace and must follow index or alias naming rules. Returns `404` if the referenced data source does not exist.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-put-dataset | Elasticsearch API documentation}
    */
  async putDataset (this: That, params: T.EsqlPutDatasetRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlPutDatasetResponse>
  async putDataset (this: That, params: T.EsqlPutDatasetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlPutDatasetResponse, unknown>>
  async putDataset (this: That, params: T.EsqlPutDatasetRequest, options?: TransportRequestOptions): Promise<T.EsqlPutDatasetResponse>
  async putDataset (this: That, params: T.EsqlPutDatasetRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath,
      body: acceptedBody,
      query: acceptedQuery
    } = this[kAcceptedParams]['esql.put_dataset']

    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 (acceptedBody.includes(key)) {
        body = body ?? {}
        // @ts-expect-error
        body[key] = params[key]
      } else if (acceptedPath.includes(key)) {
        continue
      } else if (key !== 'body' && key !== 'querystring') {
        if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) {
          // @ts-expect-error
          querystring[key] = params[key]
        } else {
          body = body ?? {}
          // @ts-expect-error
          body[key] = params[key]
        }
      }
    }

    const method = 'PUT'
    const path = `/_query/dataset/${encodeURIComponent(params.name.toString())}`
    const meta: TransportRequestMetadata = {
      name: 'esql.put_dataset',
      pathParts: {
        name: params.name
      },
      acceptedParams: {
        path: ['name'],
        body: ['data_source', 'resource', 'description', 'mappings', 'settings'],
        query: ['master_timeout', 'timeout']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Create or update an ES|QL view.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch#TODO | Elasticsearch API documentation}
    */
  async putView (this: That, params: T.EsqlPutViewRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlPutViewResponse>
  async putView (this: That, params: T.EsqlPutViewRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlPutViewResponse, unknown>>
  async putView (this: That, params: T.EsqlPutViewRequest, options?: TransportRequestOptions): Promise<T.EsqlPutViewResponse>
  async putView (this: That, params: T.EsqlPutViewRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath,
      body: acceptedBody,
      query: acceptedQuery
    } = this[kAcceptedParams]['esql.put_view']

    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 (acceptedBody.includes(key)) {
        body = body ?? {}
        // @ts-expect-error
        body[key] = params[key]
      } else if (acceptedPath.includes(key)) {
        continue
      } else if (key !== 'body' && key !== 'querystring') {
        if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) {
          // @ts-expect-error
          querystring[key] = params[key]
        } else {
          body = body ?? {}
          // @ts-expect-error
          body[key] = params[key]
        }
      }
    }

    const method = 'PUT'
    const path = `/_query/view/${encodeURIComponent(params.name.toString())}`
    const meta: TransportRequestMetadata = {
      name: 'esql.put_view',
      pathParts: {
        name: params.name
      },
      acceptedParams: {
        path: ['name'],
        body: ['query'],
        query: []
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }

  /**
    * Run an ES|QL query. Get search results for an ES|QL (Elasticsearch query language) query.
    * @see {@link https://www.elastic.co/docs/explore-analyze/query-filter/languages/esql-rest | Elasticsearch API documentation}
    */
  async query (this: That, params: T.EsqlQueryRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlQueryResponse>
  async query (this: That, params: T.EsqlQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlQueryResponse, unknown>>
  async query (this: That, params: T.EsqlQueryRequest, options?: TransportRequestOptions): Promise<T.EsqlQueryResponse>
  async query (this: That, params: T.EsqlQueryRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath,
      body: acceptedBody,
      query: acceptedQuery
    } = this[kAcceptedParams]['esql.query']

    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 (acceptedBody.includes(key)) {
        body = body ?? {}
        // @ts-expect-error
        body[key] = params[key]
      } else if (acceptedPath.includes(key)) {
        continue
      } else if (key !== 'body' && key !== 'querystring') {
        if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) {
          // @ts-expect-error
          querystring[key] = params[key]
        } else {
          body = body ?? {}
          // @ts-expect-error
          body[key] = params[key]
        }
      }
    }

    const method = 'POST'
    const path = '/_query'
    const meta: TransportRequestMetadata = {
      name: 'esql.query',
      acceptedParams: {
        path: [],
        body: ['columnar', 'filter', 'time_zone', 'locale', 'params', 'profile', 'query', 'tables', 'include_ccs_metadata', 'include_execution_metadata', 'project_routing', 'settings'],
        query: ['format', 'delimiter', 'drop_null_columns', 'allow_partial_results']
      }
    }
    return await this.transport.request({ path, method, querystring, body, meta }, options)
  }
}
