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

import { APIResource } from '../../core/resource';
import { APIPromise } from '../../core/api-promise';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';

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

  /**
   * Deletes additional audio tracks on a video. Deleting a default audio track is
   * not allowed. You must assign another audio track as default prior to deletion.
   *
   * @example
   * ```ts
   * const audioTrack = await client.stream.audioTracks.delete(
   *   'ea95132c15732412d22c1476fa83f27a',
   *   {
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *     identifier: 'ea95132c15732412d22c1476fa83f27a',
   *   },
   * );
   * ```
   */
  delete(
    audioIdentifier: string,
    params: AudioTrackDeleteParams,
    options?: RequestOptions,
  ): APIPromise<AudioTrackDeleteResponse> {
    const { account_id, identifier } = params;
    return (
      this._client.delete(
        path`/accounts/${account_id}/stream/${identifier}/audio/${audioIdentifier}`,
        options,
      ) as APIPromise<{ result: AudioTrackDeleteResponse }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Adds an additional audio track to a video using the provided audio track URL.
   *
   * @example
   * ```ts
   * const audio = await client.stream.audioTracks.copy(
   *   'ea95132c15732412d22c1476fa83f27a',
   *   {
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *     label: 'director commentary',
   *   },
   * );
   * ```
   */
  copy(identifier: string, params: AudioTrackCopyParams, options?: RequestOptions): APIPromise<Audio> {
    const { account_id, ...body } = params;
    return (
      this._client.post(path`/accounts/${account_id}/stream/${identifier}/audio/copy`, {
        body,
        ...options,
      }) as APIPromise<{ result: Audio }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Edits additional audio tracks on a video. Editing the default status of an audio
   * track to `true` will mark all other audio tracks on the video default status to
   * `false`.
   *
   * @example
   * ```ts
   * const audio = await client.stream.audioTracks.edit(
   *   'ea95132c15732412d22c1476fa83f27a',
   *   {
   *     account_id: '023e105f4ecef8ad9ca31a8372d0c353',
   *     identifier: 'ea95132c15732412d22c1476fa83f27a',
   *   },
   * );
   * ```
   */
  edit(audioIdentifier: string, params: AudioTrackEditParams, options?: RequestOptions): APIPromise<Audio> {
    const { account_id, identifier, ...body } = params;
    return (
      this._client.patch(path`/accounts/${account_id}/stream/${identifier}/audio/${audioIdentifier}`, {
        body,
        ...options,
      }) as APIPromise<{ result: Audio }>
    )._thenUnwrap((obj) => obj.result);
  }

  /**
   * Lists additional audio tracks on a video. Note this API will not return
   * information for audio attached to the video upload.
   *
   * @example
   * ```ts
   * const audioTrack = await client.stream.audioTracks.get(
   *   'ea95132c15732412d22c1476fa83f27a',
   *   { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
   * );
   * ```
   */
  get(
    identifier: string,
    params: AudioTrackGetParams,
    options?: RequestOptions,
  ): APIPromise<AudioTrackGetResponse> {
    const { account_id } = params;
    return (
      this._client.get(path`/accounts/${account_id}/stream/${identifier}/audio`, options) as APIPromise<{
        result: AudioTrackGetResponse;
      }>
    )._thenUnwrap((obj) => obj.result);
  }
}
export class AudioTracks extends BaseAudioTracks {}

export interface Audio {
  /**
   * Denotes whether the audio track will be played by default in a player.
   */
  default?: boolean;

  /**
   * A string to uniquely identify the track amongst other audio track labels for the
   * specified video.
   */
  label?: string;

  /**
   * Specifies the processing status of the video.
   */
  status?: 'queued' | 'ready' | 'error';

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

export type AudioTrackDeleteResponse = string;

export interface AudioTrackGetResponse {
  /**
   * Array of audio tracks for the video.
   */
  audio?: Array<Audio>;
}

export interface AudioTrackDeleteParams {
  /**
   * The account identifier tag.
   */
  account_id: string;

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

export interface AudioTrackCopyParams {
  /**
   * Path param: The account identifier tag.
   */
  account_id: string;

  /**
   * Body param: A string to uniquely identify the track amongst other audio track
   * labels for the specified video.
   */
  label: string;

  /**
   * Body param: An audio track URL. The server must be publicly routable and support
   * `HTTP HEAD` requests and `HTTP GET` range requests. The server should respond to
   * `HTTP HEAD` requests with a `content-range` header that includes the size of the
   * file.
   */
  url?: string;
}

export interface AudioTrackEditParams {
  /**
   * Path param: The account identifier tag.
   */
  account_id: string;

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

  /**
   * Body param: Denotes whether the audio track will be played by default in a
   * player.
   */
  default?: boolean;

  /**
   * Body param: A string to uniquely identify the track amongst other audio track
   * labels for the specified video.
   */
  label?: string;
}

export interface AudioTrackGetParams {
  /**
   * The account identifier tag.
   */
  account_id: string;
}

export declare namespace AudioTracks {
  export {
    type Audio as Audio,
    type AudioTrackDeleteResponse as AudioTrackDeleteResponse,
    type AudioTrackGetResponse as AudioTrackGetResponse,
    type AudioTrackDeleteParams as AudioTrackDeleteParams,
    type AudioTrackCopyParams as AudioTrackCopyParams,
    type AudioTrackEditParams as AudioTrackEditParams,
    type AudioTrackGetParams as AudioTrackGetParams,
  };
}
