/**
 * Type declarations for @distube/ytdl-core
 * @see https://www.npmjs.com/package/@distube/ytdl-core
 */

declare module "@distube/ytdl-core" {
  export interface VideoDetails {
    title: string;
    author?: {
      name: string;
      user?: string;
      channel_url?: string;
    };
    lengthSeconds: string;
    viewCount?: string;
    thumbnails?: Array<{ url: string; width?: number; height?: number }>;
    description?: string;
    media?: Record<string, string>;
  }

  export interface Format {
    itag: number;
    url: string;
    mimeType?: string;
    quality?: string;
    qualityLabel?: string;
    audioQuality?: string;
    hasVideo: boolean;
    hasAudio: boolean;
    container?: string;
    codecs?: string;
    width?: number;
    height?: number;
    fps?: number;
    bitrate?: number;
    audioBitrate?: number;
    duration?: string;
  }

  export interface VideoInfo {
    videoDetails: VideoDetails;
    formats: Format[];
    related_videos?: unknown[];
  }

  export function getInfo(url: string): Promise<VideoInfo>;
  export function getInfo(videoId: string): Promise<VideoInfo>;
  export function getURLVideoID(url: string): string;
  export function getVideoID(url: string): string;
  export function chooseFormat(
    formats: Format[],
    options?: { quality?: string; filter?: string }
  ): Format | undefined;
  export function filterFormats(
    formats: Format[],
    filter: string
  ): Format[];
  export function validateID(id: string): boolean;
  export function validateURL(url: string): boolean;

  const ytdl: {
    (url: string, options?: unknown): NodeJS.ReadableStream;
    getInfo: typeof getInfo;
    getURLVideoID: typeof getURLVideoID;
    getVideoID: typeof getVideoID;
    chooseFormat: typeof chooseFormat;
    filterFormats: typeof filterFormats;
    validateID: typeof validateID;
    validateURL: typeof validateURL;
  };

  export default ytdl;
}