/*
 * 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[] }> = {
  capabilities: {
    path: [],
    body: [],
    query: [
      'method',
      'path',
      'parameters',
      'capabilities',
      'local_only',
      'timeout'
    ]
  }
}

/**
  * Checks if the specified combination of method, API, parameters, and arbitrary capabilities are supported.
  * @see {@link https://github.com/elastic/elasticsearch/blob/main/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc#require-or-skip-api-capabilities | Elasticsearch API documentation}
  */
export default async function CapabilitiesApi (this: That, params?: T.CapabilitiesRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.CapabilitiesResponse>
export default async function CapabilitiesApi (this: That, params?: T.CapabilitiesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CapabilitiesResponse, unknown>>
export default async function CapabilitiesApi (this: That, params?: T.CapabilitiesRequest, options?: TransportRequestOptions): Promise<T.CapabilitiesResponse>
export default async function CapabilitiesApi (this: That, params?: T.CapabilitiesRequest, options?: TransportRequestOptions): Promise<any> {
  const {
    path: acceptedPath
  } = acceptedParams.capabilities

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