import type {
  TXVoiceChangerType,
  TXVoiceReverbType,
  AudioMusicParam,
} from './trtc_cloud_def';

/// Management class for background music, short audio effects, and voice effects
export default class TXAudioEffectManager {
  private nativeSdk: any;

  constructor(trtcReactNativeSdk: any) {
    this.nativeSdk = trtcReactNativeSdk;
  }

  /**
  - Enabling in-ear monitoring
  - After enabling in-ear monitoring, anchors can hear in earphones their own voice captured by the mic. This is designed for singing scenarios.
  - In-ear monitoring cannot be enabled for Bluetooth earphones. This is because Bluetooth earphones have high latency. Please ask anchors to use wired earphones via a UI reminder.
  - Given that not all phones deliver excellent in-ear monitoring effects, we have blocked this feature on some phones.
  @param enable `true`: enable, `false`: disable
  */
  enableVoiceEarMonitor(enable: boolean): Promise<void> {
    return this.nativeSdk.enableVoiceEarMonitor({ enable });
  }
  /**
  - Setting in-ear monitoring volume
  @param volume	Volume. Value range: 0-100; default: 100
  */
  setVoiceEarMonitorVolume(volume: number): Promise<void> {
    return this.nativeSdk.setVoiceEarMonitorVolume({ volume });
  }
  /**
  - Setting voice reverb effects
  @param type	Default Value: TXVoiceReverbType.TXLiveVoiceReverbType_0
  */
  setVoiceReverbType(type: TXVoiceReverbType): Promise<void> {
    return this.nativeSdk.setVoiceReverbType({ type });
  }
  /**
  - Setting voice changing effects
  @param type	Default Value: TXVoiceChangerType.TXLiveVoiceChangerType_0
  */
  setVoiceChangerType(type: TXVoiceChangerType): Promise<void> {
    return this.nativeSdk.setVoiceChangerType({ type });
  }
  /**
  - Setting speech volume
  @param volume	Volume. Value range: 0-100; default: 100
   */
  setVoiceCaptureVolume(volume: number): Promise<void> {
    return this.nativeSdk.setVoiceCaptureVolume({ volume });
  }
  /**
  - Starting background music
  - You must assign an ID to each music track so that you can start, stop, or set the volume of music tracks by ID.
  @param musicParam	Music parameter
  @return true: Success; false: Failure
  */
  startPlayMusic(musicParam: AudioMusicParam): Promise<boolean> {
    return this.nativeSdk.startPlayMusic({
      musicParam: JSON.stringify(musicParam),
    });
  }
  /**
  - Stopping background music
  @param id Music ID
  */
  stopPlayMusic(id: number): Promise<void> {
    return this.nativeSdk.stopPlayMusic({ id: id });
  }
  /**
  - Pausing background music
  @param id	Music ID
  */
  pausePlayMusic(id: number): Promise<void> {
    return this.nativeSdk.pausePlayMusic({ id: id });
  }
  /**
  - Resuming background music
  @param id	Music ID
  */
  resumePlayMusic(id: number): Promise<void> {
    return this.nativeSdk.resumePlayMusic({ id: id });
  }
  /**
  - Setting the remote playback volume of a specific music track
  - This API is used to control the remote playback volume (the volume heard by audience) of a specific music track.
  @param id	Music ID
  @param volume	Volume. Value range: 0-100; default: 60
  */
  setMusicPublishVolume(id: number, volume: number): Promise<void> {
    return this.nativeSdk.setMusicPublishVolume({ id: id, volume: volume });
  }

  /**
  - Setting the local playback volume of a specific music track
  - This API is used to control the local playback volume (the volume heard by anchors) of a specific music track.
  @param id	Music ID
  @param volume	Volume. Value range: 0-100; default: 60
  */
  setMusicPlayoutVolume(id: number, volume: number): Promise<void> {
    return this.nativeSdk.setMusicPlayoutVolume({ id: id, volume: volume });
  }
  /**
  - Setting the local and remote playback volume of background music
  - This API is used to set the local and remote playback volume of background music.
    - Local volume: the volume of music heard by anchors
    - Remote volume: the volume of music heard by audience
  @param volume	Volume. Value range: 0-100; default: 60
  */
  setAllMusicVolume(volume: number): Promise<void> {
    return this.nativeSdk.setAllMusicVolume({ volume: volume });
  }
  /**
  - Adjusting the pitch of background music
  @param id	Music ID
  @param pitch	Pitch. Value range: floating point numbers in the range of [-1, 1]; default: 0.0f
  */
  setMusicPitch(id: number, pitch: number): Promise<void> {
    return this.nativeSdk.setMusicPitch({
      id: id,
      pitch: pitch.toString(),
    });
  }
  /**
  - Changing the speed of background music
  @param id	Music ID
  @param speedRate	Music speed. Value range: floating point numbers in the range of [0.5, 2]; default: 1.0f
  */
  setMusicSpeedRate(id: number, speedRate: number): Promise<void> {
    return this.nativeSdk.setMusicSpeedRate({
      id: id,
      speedRate: speedRate.toString(),
    });
  }
  /**
  - Getting the playback progress (ms) of background music
  @param id	Music ID
  @return The milliseconds that have passed since playback started. -1 indicates failure to get the the playback progress.
  */
  getMusicCurrentPosInMS(id: number): Promise<number> {
    return this.nativeSdk.getMusicCurrentPosInMS({ id: id });
  }
  /**
  - Setting the playback progress (ms) of background music
  @param id	Music ID
  @param pts	Unit: millisecond
  */
  seekMusicToPosInMS(id: number, pts: number): Promise<void> {
    return this.nativeSdk.seekMusicToPosInMS({ id: id, pts: pts });
  }
  /**
  - Getting the total length (ms) of background music
  @param path	Path of the music file.
  @return The length of the specified music file is returned. -1 indicates failure to get the length.
  */
  getMusicDurationInMS(path: string): Promise<number> {
    return this.nativeSdk.getMusicDurationInMS({ path: path });
  }
}
