/*
 * 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[] }>
}

export default class Streams {
  transport: Transport
  [kAcceptedParams]: Record<string, { path: string[], body: string[], query: string[] }>
  constructor (transport: Transport) {
    this.transport = transport
    this[kAcceptedParams] = {
      'streams.logs_disable': {
        path: [
          'name'
        ],
        body: [],
        query: [
          'master_timeout',
          'timeout'
        ]
      },
      'streams.logs_enable': {
        path: [
          'name'
        ],
        body: [],
        query: [
          'master_timeout',
          'timeout'
        ]
      },
      'streams.status': {
        path: [],
        body: [],
        query: [
          'master_timeout'
        ]
      }
    }
  }

  /**
    * Disable a named stream. Turn off the named stream feature for this cluster.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch#TODO | Elasticsearch API documentation}
    */
  async logsDisable (this: That, params: T.StreamsLogsDisableRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.StreamsLogsDisableResponse>
  async logsDisable (this: That, params: T.StreamsLogsDisableRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.StreamsLogsDisableResponse, unknown>>
  async logsDisable (this: That, params: T.StreamsLogsDisableRequest, options?: TransportRequestOptions): Promise<T.StreamsLogsDisableResponse>
  async logsDisable (this: That, params: T.StreamsLogsDisableRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['streams.logs_disable']

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

  /**
    * Enable a named stream. Turn on the named stream feature for this cluster. NOTE: To protect existing data, this feature can be turned on only if the cluster does not have existing indices or data streams that match the pattern `<name>|<name>.*` for the enabled stream type name. If those indices or data streams exist, a `409 - Conflict` response and error is returned.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch#TODO | Elasticsearch API documentation}
    */
  async logsEnable (this: That, params: T.StreamsLogsEnableRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.StreamsLogsEnableResponse>
  async logsEnable (this: That, params: T.StreamsLogsEnableRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.StreamsLogsEnableResponse, unknown>>
  async logsEnable (this: That, params: T.StreamsLogsEnableRequest, options?: TransportRequestOptions): Promise<T.StreamsLogsEnableResponse>
  async logsEnable (this: That, params: T.StreamsLogsEnableRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['streams.logs_enable']

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

  /**
    * Get the status of streams. Get the current status for all types of streams.
    * @see {@link https://www.elastic.co/docs/api/doc/elasticsearch#TODO | Elasticsearch API documentation}
    */
  async status (this: That, params?: T.StreamsStatusRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.StreamsStatusResponse>
  async status (this: That, params?: T.StreamsStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.StreamsStatusResponse, unknown>>
  async status (this: That, params?: T.StreamsStatusRequest, options?: TransportRequestOptions): Promise<T.StreamsStatusResponse>
  async status (this: That, params?: T.StreamsStatusRequest, options?: TransportRequestOptions): Promise<any> {
    const {
      path: acceptedPath
    } = this[kAcceptedParams]['streams.status']

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