// Full Stremio addon protocol TypeScript types

export type ContentType = 'movie' | 'series' | 'channel' | 'tv' | 'anime' | 'other';

export interface ResourceDescriptor {
  name: string;
  types?: ContentType[];
  idPrefixes?: string[];
}

export interface ExtraDescriptor {
  name: string;
  isRequired?: boolean;
  options?: string[];
  optionsLimit?: number;
}

export interface CatalogDescriptor {
  type: ContentType;
  id: string;
  name: string;
  extra?: ExtraDescriptor[];
}

export interface ConfigOption {
  key: string;
  type: 'text' | 'number' | 'password' | 'checkbox' | 'select';
  title?: string;
  required?: boolean;
  options?: string[];
  default?: string;
}

export interface AddonManifest {
  id: string;
  version: string;
  name: string;
  description?: string;
  logo?: string;
  background?: string;
  contactEmail?: string;
  types: ContentType[];
  resources: (string | ResourceDescriptor)[];
  catalogs: CatalogDescriptor[];
  idPrefixes?: string[];
  behaviorHints?: {
    adult?: boolean;
    p2p?: boolean;
    configurable?: boolean;
    configurationRequired?: boolean;
  };
  config?: ConfigOption[];
}

export interface InstalledAddon {
  manifest: AddonManifest;
  transportUrl: string;
  enabled: boolean;
  installedAt: number;
}

export interface MetaPreview {
  id: string;
  type: ContentType;
  name: string;
  poster?: string;
  posterShape?: 'square' | 'regular' | 'landscape';
  background?: string;
  logo?: string;
  description?: string;
  releaseInfo?: string;
  imdbRating?: string;
  genres?: string[];
  links?: Link[];
}

export interface Link {
  name: string;
  category: string;
  url: string;
}

export interface Video {
  id: string;
  title: string;
  season?: number;
  episode?: number;
  released?: string;
  overview?: string;
  thumbnail?: string;
  streams?: Stream[];
}

export interface Trailer {
  source: string;
  type: 'Trailer' | 'Clip';
}

export interface MetaDetail extends MetaPreview {
  cast?: string[];
  director?: string[];
  writer?: string[];
  awards?: string;
  website?: string;
  runtime?: string;
  language?: string;
  country?: string;
  trailers?: Trailer[];
  videos?: Video[];
  behaviorHints?: {
    defaultVideoId?: string;
    hasScheduledVideos?: boolean;
  };
}

export interface SubtitleTrack {
  id: string;
  url: string;
  lang: string;
  label?: string;
}

export interface Stream {
  url?: string;
  ytId?: string;
  infoHash?: string;
  fileIdx?: number;
  externalUrl?: string;
  name?: string;
  title?: string;
  description?: string;
  subtitles?: SubtitleTrack[];
  behaviorHints?: {
    notWebReady?: boolean;
    bingeGroup?: string;
    countryWhitelist?: string[];
    countryBlacklist?: string[];
    proxyHeaders?: {
      request?: Record<string, string>;
      response?: Record<string, string>;
    };
    videoHash?: string;
    videoSize?: number;
    filename?: string;
  };
}

export interface CatalogResponse {
  metas: MetaPreview[];
  hasMore?: boolean;
}

export interface MetaResponse {
  meta: MetaDetail;
}

export interface StreamResponse {
  streams: Stream[];
}

export interface SubtitleResponse {
  subtitles: SubtitleTrack[];
}

export interface AddonStreamResult {
  addon: AddonManifest;
  streams: Stream[];
  isDebridCached?: boolean;
}
