/**
 * The `Stream` class is responsible for handling audio, video, and screen-sharing streams.
 */
export class Stream {
  /**
   * This represents a unique identifier assigned to the stream.
   */
  id: string;

  /**
   * This represents the kind of the stream.
   */
  kind: "audio" | "video" | "share" | "shareAudio";

  /**
   * This represents the codec used to encode and decode the stream.
   */
  codec: string;

  /**
   * This represents the underlying media track associated with the stream.
   */
  track: MediaStreamTrack;

  /**
   * This represents whether the stream is currently paused.
   */
  paused: boolean;

  /**
   * - This method can be used to resume the stream for a remote participant.
   */
  resume(): void;

  /**
   * - This method can be used to pause the stream for a remote participant.
   */
  pause(): void;

  /**
   * Registers an event listener.
   * @param eventType Event name to which you want to subscribe.
   * @param listener A callback function that is executed when the specified event is emitted.
   *
   * To view the complete list of available events and their details, refer to {@link StreamEvent}.
   */
  on(eventType: "state", listener: (data: any) => void): void;

  /**
   * Removes an event listener that was previously registered.
   *
   * @param eventType Event name to which you want to unsubscribe.
   * @param listener Callback function which was passed while subscribing to the event.
   *
   * To view the complete list of available events and their details, refer to  {@link StreamEvent}.
   */
  off(eventType: "state", listener: (data: any) => void): void;
}

export type StreamEvent = {
  /**
   * @event
   *
   * - Triggered when the state of a video or screen-share stream changes.
   *
   * - This event helps track whether the stream is active, stuck, frozen,recovered, or ended.
   *
   * > **Note**
   * >
   * > This event is emitted **only for remote participants** and applies
   * > specifically to **video and screen-share streams**.
   *
   * @param data
   *
   * @param data.state
   * The current state of the stream:
   *
   * - `"active"` — The stream is functioning normally.
   * - `"stuck"` — The stream is no longer progressing as expected.
   * - `"freeze-detected"` — A freeze in the video stream has been detected.
   * - `"freeze-resolved"` — The previously detected freeze has been resolved.
   * - `"ended"` — The stream has ended.
   *
   * @param data.timestamp
   * Timestamp (in milliseconds since epoch) indicating when the state change occurred.
   *
   * @example
   * ```ts
   * stream.on("state", ({ state, timestamp }) => {
   *   // Handle stream state changes
   * });
   * ```
   * @returns
   */
  state: (data: {
    state: string;
    timestamp: number;
  }) => void;
};
