// ── Addon Registry Data Models ──

export interface AddonRegistryEntry {
  /** Unique addon identifier */
  id: string;
  /** Display name */
  name: string;
  /** Short description */
  description: string;
  /** Addon version */
  version: string;
  /** Base manifest URL (the canonical manifest.json endpoint — before user configuration) */
  baseManifestUrl: string;
  /** Manifest URL (alias for baseManifestUrl, kept for backward compat) */
  manifestUrl: string;
  /** Install URL (base URL for Stremio addon installation) */
  installUrl: string;
  /** Full configured-manifest URL template, if known (e.g. "https://example.com/{debridToken}/manifest.json") */
  configureUrl: string | null;
  /** Logo URL */
  logo: string | null;
  /** Background art URL */
  background: string | null;
  /** Resources this addon provides (stream, catalog, meta, subtitles) */
  resources: string[];
  /** Content types supported (movie, series, anime, tv, other) */
  types: string[];
  /** ID prefixes for content lookup */
  idPrefixes: string[];
  /** Catalog definitions if this addon provides catalogs */
  catalogs: AddonCatalogDef[];
  /** Debrid services supported */
  supportedDebridServices: string[];
  /** Whether this addon requires debrid to function */
  requiresDebrid: boolean;
  /** Whether this addon is configurable (has behaviorHints.configurable) */
  configurable: boolean;
  /** Whether configuration is required for this addon to function */
  configurationRequired: boolean;
  /** Health status */
  health: AddonHealthStatus;
  /** Whether this addon is enabled by default for new users */
  enabledByDefault: boolean;
  /** Is this addon part of a recommended preset */
  inPresets: string[];
  /** Is this addon deprecated */
  deprecated: boolean;
  /** Is this addon fallback-only (not in primary sources) */
  fallbackOnly: boolean;
  /** GitHub source repo URL */
  sourceRepo: string | null;
  /** License identifier */
  license: string | null;
  /** Last time manifest was fetched/verified */
  lastChecked: string | null;
  /** Category: streams, catalogs, subtitles, anime, utility */
  category: string;
}

export interface AddonCatalogDef {
  type: string;
  id: string;
  name: string;
  extra?: { name: string; isRequired?: boolean; options?: string[] }[];
}

export type AddonHealthStatus =
  | "online"
  | "slow"
  | "failing"
  | "auth_error"
  | "offline"
  | "deprecated"
  | "unknown";

export interface AddonHealthCheckResult {
  addonId: string;
  status: AddonHealthStatus;
  manifestResponseMs: number;
  streamResponseMs: number | null;
  manifestValid: boolean;
  streamCount: number | null;
  error: string | null;
  checkedAt: string;
}

export interface AddonPreset {
  id: string;
  name: string;
  description: string;
  addonIds: string[];
}

export interface AddonRegistryResponse {
  addons: AddonRegistryEntry[];
  presets: AddonPreset[];
  updatedAt: string;
}

export interface AddonStatusResponse {
  addons: {
    id: string;
    name: string;
    health: AddonHealthStatus;
    lastChecked: string | null;
    manifestResponseMs: number | null;
  }[];
}
