export type MediaType = 'movie' | 'show' | 'game'

export type MediaProvider = 'tmdb' | 'igdb'

export type ThemeMode = 'dark' | 'light' | 'system'

export type UserRole = 'user' | 'admin'

export interface AuthUser {
  id: string
  email: string
  displayName: string
  role: UserRole
  createdAt?: string
  updatedAt?: string
}

export interface AuthResult {
  accessToken: string
  refreshToken: string
  expiresAt: string
  user: AuthUser
}

export interface MediaItem {
  id: number
  provider: MediaProvider
  providerId: number
  title: string
  overview: string
  type: MediaType
  releaseDate: string
  genres: string[]
  platforms: string[]
  rating: number
  runtimeMinutes: number
  artworkKey: string
}

export interface TVShowItem extends MediaItem {
  type: 'show'
  seasonCount: number
  episodeCount: number
}

export interface EpisodeProgress {
  itemId: number
  seasonNumber: number
  episodeNumber: number
  progressPercent: number
  lastWatchedAt: string
}

export interface ProgressUpdateInput {
  mediaId: number
  seasonNumber: number
  episodeNumber: number
  progressPercent: number
}

export type DownloadStatus = 'queued' | 'downloading' | 'stalled' | 'completed' | 'failed'

export interface DownloadJob {
  id: string
  title: string
  status: DownloadStatus
  progressPercent: number
  downloadSpeedMbps: number
  etaMinutes: number
  sourceType: 'magnet' | 'torrent' | 'direct' | 'http'
}

export interface RecommendationItem {
  id: number
  reason: string
  score: number
  media: MediaItem
}

export interface ContinueWatchingItem {
  item: MediaItem
  progress: EpisodeProgress
}

export interface DashboardPayload {
  watchLater: MediaItem[]
  gameBacklog: MediaItem[]
  activeDownloads: DownloadJob[]
  recommendations: RecommendationItem[]
  trending: MediaItem[]
  upcoming: MediaItem[]
  recentlyWatched: MediaItem[]
}

export type DiscoverSectionKind =
  | 'trending'
  | 'popular'
  | 'top-rated'
  | 'upcoming'
  | 'now-playing'
  | 'airing-today'
  | 'recently-released-games'
  | 'most-anticipated-games'
  | 'indie-highlights'
  | 'genre'

export interface DiscoverSection {
  kind: DiscoverSectionKind
  title: string
  subtitle: string
  items: MediaItem[]
}

export interface DiscoverParams {
  page?: number
  pageSize?: number
  query?: string
  genre?: string
  mediaType?: MediaType | 'all'
}

export interface SearchFilters {
  genre?: string
  mediaType?: MediaType | 'all'
}

export interface SearchResult {
  id: number
  mediaType: MediaType
  title: string
  subtitle: string
  genres: string[]
  score: number
}

export type ApiStatus = 'idle' | 'loading' | 'success' | 'error'

export interface ApiState<T> {
  status: ApiStatus
  data: T | null
  error: string | null
}
