// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../../../core/resource';
import * as CaptionsAPI from '../captions';
import * as VttAPI from './vtt';
import { BaseVtt, Vtt, VttGetParams, VttGetResponse } from './vtt';
import { APIPromise } from '../../../../core/api-promise';
import { RequestOptions } from '../../../../internal/request-options';
import { multipartFormRequestOptions } from '../../../../internal/uploads';
import { path } from '../../../../internal/utils/path';

export class BaseLanguage extends APIResource {
  static override readonly _key: readonly ['stream', 'captions', 'language'] = Object.freeze([
    'stream',
    'captions',
    'language',
  ] as const);

  /**
   * Generate captions or subtitles for provided language via AI.
   *
   * @example
   * ```ts
   * const caption =
   *   await client.stream.captions.language.create('tr', {
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *     identifier: 'ea95132c15732412d22c1476fa83f27a',
   *   });
   * ```
   */
  create(
    language: string,
    params: LanguageCreateParams,
    options?: RequestOptions,
  ): APIPromise<CaptionsAPI.Caption> {
    const { account_id, identifier } = params;
    return (
      this._client.post(
        path`/accounts/${account_id}/stream/${identifier}/captions/${language}/generate`,
        options,
      ) as APIPromise<{ result: CaptionsAPI.Caption }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Uploads the caption or subtitle file to the endpoint for a specific BCP47
   * language. One caption or subtitle file per language is allowed.
   *
   * @example
   * ```ts
   * const caption =
   *   await client.stream.captions.language.update('tr', {
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *     identifier: 'ea95132c15732412d22c1476fa83f27a',
   *     file: '@/Users/kyle/Desktop/tr.vtt',
   *   });
   * ```
   */
  update(
    language: string,
    params: LanguageUpdateParams,
    options?: RequestOptions,
  ): APIPromise<CaptionsAPI.Caption> {
    const { account_id, identifier, ...body } = params;
    return (
      this._client.put(
        path`/accounts/${account_id}/stream/${identifier}/captions/${language}`,
        multipartFormRequestOptions({ body, ...options }, this._client),
      ) as APIPromise<{ result: CaptionsAPI.Caption }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Removes the captions or subtitles from a video.
   *
   * @example
   * ```ts
   * const language =
   *   await client.stream.captions.language.delete('tr', {
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *     identifier: 'ea95132c15732412d22c1476fa83f27a',
   *   });
   * ```
   */
  delete(
    language: string,
    params: LanguageDeleteParams,
    options?: RequestOptions,
  ): APIPromise<LanguageDeleteResponse> {
    const { account_id, identifier } = params;
    return (
      this._client.delete(
        path`/accounts/${account_id}/stream/${identifier}/captions/${language}`,
        options,
      ) as APIPromise<{ result: LanguageDeleteResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Lists the captions or subtitles for provided language.
   *
   * @example
   * ```ts
   * const caption = await client.stream.captions.language.get(
   *   'tr',
   *   {
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *     identifier: 'ea95132c15732412d22c1476fa83f27a',
   *   },
   * );
   * ```
   */
  get(
    language: string,
    params: LanguageGetParams,
    options?: RequestOptions,
  ): APIPromise<CaptionsAPI.Caption> {
    const { account_id, identifier } = params;
    return (
      this._client.get(
        path`/accounts/${account_id}/stream/${identifier}/captions/${language}`,
        options,
      ) as APIPromise<{ result: CaptionsAPI.Caption }>
    )._thenUnwrap((obj) => obj.result);
  }
}
export class Language extends BaseLanguage {
  vtt: VttAPI.Vtt = new VttAPI.Vtt(this._client);
}

export type LanguageDeleteResponse = string;

export interface LanguageCreateParams {
  /**
   * Identifier.
   */
  account_id: string;

  /**
   * A Cloudflare-generated unique identifier for a media item.
   */
  identifier: string;
}

export interface LanguageUpdateParams {
  /**
   * Path param: Identifier.
   */
  account_id: string;

  /**
   * Path param: A Cloudflare-generated unique identifier for a media item.
   */
  identifier: string;

  /**
   * Body param: The WebVTT file containing the caption or subtitle content.
   */
  file: string;
}

export interface LanguageDeleteParams {
  /**
   * Identifier.
   */
  account_id: string;

  /**
   * A Cloudflare-generated unique identifier for a media item.
   */
  identifier: string;
}

export interface LanguageGetParams {
  /**
   * Identifier.
   */
  account_id: string;

  /**
   * A Cloudflare-generated unique identifier for a media item.
   */
  identifier: string;
}

Language.Vtt = Vtt;
Language.BaseVtt = BaseVtt;

export declare namespace Language {
  export {
    type LanguageDeleteResponse as LanguageDeleteResponse,
    type LanguageCreateParams as LanguageCreateParams,
    type LanguageUpdateParams as LanguageUpdateParams,
    type LanguageDeleteParams as LanguageDeleteParams,
    type LanguageGetParams as LanguageGetParams,
  };

  export {
    Vtt as Vtt,
    BaseVtt as BaseVtt,
    type VttGetResponse as VttGetResponse,
    type VttGetParams as VttGetParams,
  };
}
