import type {
  ContinueWatchingItem,
  DashboardPayload,
  DiscoverSection,
  MediaItem,
  RecommendationItem,
} from '@/types/domain'

const createMedia = (
  id: number,
  provider: 'tmdb' | 'igdb',
  providerId: number,
  title: string,
  type: 'movie' | 'show' | 'game',
  genres: string[],
  platforms: string[],
  releaseDate: string,
  rating: number,
  runtimeMinutes: number,
): MediaItem => ({
  id,
  provider,
  providerId,
  title,
  overview:
    type === 'movie'
      ? `${title} is a cinematic journey with high production value and sharp pacing.`
      : type === 'show'
        ? `${title} is a serialized story balancing character arcs with premium world-building.`
        : `${title} is a high-signal game release tracked through your IGDB-powered backlog.`,
  type,
  releaseDate,
  genres,
  platforms,
  rating,
  runtimeMinutes,
  artworkKey: `${title}-${id}`,
})

const catalog: MediaItem[] = [
  createMedia(1, 'tmdb', 10001, 'Neon Divide', 'movie', ['Sci-Fi', 'Thriller'], [], '2025-05-14', 8.5, 118),
  createMedia(2, 'tmdb', 10002, 'Last Light Harbor', 'show', ['Drama', 'Mystery'], [], '2024-09-02', 8.1, 52),
  createMedia(3, 'tmdb', 10003, 'Orbitline', 'movie', ['Sci-Fi', 'Adventure'], [], '2025-02-21', 7.9, 131),
  createMedia(4, 'tmdb', 10004, 'Static Bloom', 'show', ['Comedy', 'Drama'], [], '2023-11-12', 7.8, 42),
  createMedia(5, 'tmdb', 10005, 'Kingdom Ash', 'movie', ['Fantasy', 'Action'], [], '2024-12-08', 8.7, 143),
  createMedia(6, 'tmdb', 10006, 'Pulse District', 'show', ['Crime', 'Thriller'], [], '2025-03-18', 8.0, 48),
  createMedia(7, 'tmdb', 10007, 'The Glass Relay', 'movie', ['Action', 'Thriller'], [], '2024-07-01', 7.6, 109),
  createMedia(8, 'tmdb', 10008, 'Summer in Vanta', 'show', ['Romance', 'Drama'], [], '2025-06-30', 7.5, 44),
  createMedia(9, 'tmdb', 10009, 'Zero Meridian', 'movie', ['Sci-Fi', 'Action'], [], '2026-01-10', 8.9, 127),
  createMedia(10, 'tmdb', 10010, 'Northline 13', 'show', ['Mystery', 'Crime'], [], '2025-10-19', 8.3, 50),
  createMedia(11, 'tmdb', 10011, 'Paper Falcons', 'movie', ['Adventure', 'Family'], [], '2024-03-05', 7.4, 101),
  createMedia(12, 'tmdb', 10012, 'Hollow Anthem', 'movie', ['Drama', 'Music'], [], '2025-08-22', 8.2, 114),
  createMedia(13, 'tmdb', 10013, 'Riptide Avenue', 'show', ['Action', 'Drama'], [], '2023-04-09', 7.7, 55),
  createMedia(14, 'tmdb', 10014, 'Night Air Index', 'movie', ['Mystery', 'Thriller'], [], '2026-04-03', 8.4, 122),
  createMedia(15, 'tmdb', 10015, 'Shoreline Math', 'show', ['Comedy', 'Family'], [], '2024-06-17', 7.3, 37),
  createMedia(16, 'tmdb', 10016, 'Arcadia Wire', 'movie', ['Fantasy', 'Drama'], [], '2025-12-02', 8.6, 136),
  createMedia(17, 'tmdb', 10017, 'Abyss Echo', 'show', ['Sci-Fi', 'Mystery'], [], '2025-01-27', 8.8, 53),
  createMedia(18, 'tmdb', 10018, 'Delta Murmur', 'movie', ['Horror', 'Thriller'], [], '2024-10-29', 7.2, 96),
  createMedia(19, 'tmdb', 10019, 'Pine Weather', 'show', ['Drama', 'Romance'], [], '2025-04-11', 7.9, 46),
  createMedia(20, 'tmdb', 10020, 'Copper Atlas', 'movie', ['Adventure', 'Action'], [], '2025-09-09', 8.0, 111),
  createMedia(21, 'tmdb', 10021, 'Moonset Terminal', 'movie', ['Sci-Fi', 'Drama'], [], '2026-02-14', 8.4, 124),
  createMedia(22, 'tmdb', 10022, 'Marble Sea', 'show', ['Fantasy', 'Adventure'], [], '2024-01-22', 7.6, 49),
  createMedia(23, 'tmdb', 10023, 'Tangent Room', 'movie', ['Mystery', 'Drama'], [], '2025-11-03', 8.1, 119),
  createMedia(24, 'tmdb', 10024, 'Signal Orchard', 'show', ['Thriller', 'Drama'], [], '2025-07-18', 8.2, 51),
  createMedia(25, 'igdb', 20025, 'Star Circuit Zero', 'game', ['Action', 'Racing'], ['PC', 'PS5', 'Xbox Series X|S'], '2026-09-18', 8.8, 900),
  createMedia(26, 'igdb', 20026, 'Verdant Protocol', 'game', ['Strategy', 'Simulation'], ['PC'], '2026-11-06', 8.4, 1260),
  createMedia(27, 'igdb', 20027, 'Mythic Drift', 'game', ['Racing', 'Adventure'], ['PS5', 'Xbox Series X|S'], '2026-07-24', 8.2, 720),
  createMedia(28, 'igdb', 20028, 'Ashen Vale', 'game', ['RPG', 'Adventure'], ['PC', 'PS5'], '2026-05-15', 9.0, 1680),
  createMedia(29, 'igdb', 20029, 'Signal Breaker', 'game', ['Shooter', 'Sci-Fi'], ['PC', 'Xbox Series X|S'], '2026-02-28', 8.1, 840),
  createMedia(30, 'igdb', 20030, 'Luma Forge', 'game', ['Indie', 'Puzzle'], ['Nintendo Switch', 'PC'], '2026-01-16', 8.3, 360),
  createMedia(31, 'igdb', 20031, 'Citadel Dawn', 'game', ['Strategy', 'RPG'], ['PC'], '2026-03-05', 8.6, 1500),
  createMedia(32, 'igdb', 20032, 'Harbor Tactics', 'game', ['Strategy', 'Simulation'], ['PC'], '2025-11-21', 7.8, 1080),
  createMedia(33, 'igdb', 20033, 'Ghostline Kyoto', 'game', ['Action', 'Adventure'], ['PS5', 'PC'], '2026-02-14', 8.7, 1020),
  createMedia(34, 'igdb', 20034, 'Snowfall County', 'game', ['Simulation', 'Adventure'], ['Nintendo Switch', 'PC'], '2025-12-12', 7.9, 540),
  createMedia(35, 'igdb', 20035, 'Titan Relay', 'game', ['Shooter', 'Action'], ['PC', 'PS5'], '2026-04-22', 8.5, 780),
  createMedia(36, 'igdb', 20036, 'Wild Circuit Stories', 'game', ['Racing', 'Indie'], ['Nintendo Switch', 'Xbox Series X|S'], '2026-08-07', 8.0, 420),
]

export const genres = [
  'Sci-Fi',
  'Drama',
  'Thriller',
  'Action',
  'Fantasy',
  'Adventure',
  'Mystery',
  'Comedy',
  'Romance',
  'Crime',
  'Family',
  'Music',
  'Horror',
  'Indie',
  'Puzzle',
  'RPG',
  'Racing',
  'Shooter',
  'Simulation',
  'Strategy',
]

const recommendationFor = (media: MediaItem, reason: string, score: number): RecommendationItem => ({
  id: media.id,
  media,
  reason,
  score,
})

const byId = (id: number): MediaItem => {
  const found = catalog.find((item) => item.id === id)

  if (!found) {
    throw new Error(`Media item with id ${id} was not found in mock catalog`)
  }

  return found
}

export const continueWatchingItems: ContinueWatchingItem[] = [
  {
    item: byId(2),
    progress: {
      itemId: 2,
      seasonNumber: 1,
      episodeNumber: 7,
      progressPercent: 63,
      lastWatchedAt: '2026-03-09T21:40:00Z',
    },
  },
  {
    item: byId(17),
    progress: {
      itemId: 17,
      seasonNumber: 2,
      episodeNumber: 2,
      progressPercent: 28,
      lastWatchedAt: '2026-03-08T23:16:00Z',
    },
  },
  {
    item: byId(6),
    progress: {
      itemId: 6,
      seasonNumber: 1,
      episodeNumber: 11,
      progressPercent: 82,
      lastWatchedAt: '2026-03-07T18:10:00Z',
    },
  },
]

export const dashboardPayload: DashboardPayload = {
  watchLater: [byId(25), byId(9), byId(14), byId(33), byId(21), byId(28)],
  gameBacklog: [byId(25), byId(33), byId(28), byId(31)],
  activeDownloads: [
    {
      id: 'dl-1024',
      title: 'Zero Meridian (2160p HDR)',
      status: 'downloading',
      progressPercent: 47,
      downloadSpeedMbps: 23.8,
      etaMinutes: 19,
      sourceType: 'magnet',
    },
    {
      id: 'dl-1025',
      title: 'Star Circuit Zero preload',
      status: 'queued',
      progressPercent: 0,
      downloadSpeedMbps: 0,
      etaMinutes: 34,
      sourceType: 'http',
    },
    {
      id: 'dl-1026',
      title: 'Arcadia Wire (1080p)',
      status: 'stalled',
      progressPercent: 74,
      downloadSpeedMbps: 0.2,
      etaMinutes: 120,
      sourceType: 'torrent',
    },
  ],
  recommendations: [
    recommendationFor(byId(28), 'Because your queue trends toward expansive fantasy worlds', 93),
    recommendationFor(byId(24), 'Because you finish serial thrillers quickly', 89),
    recommendationFor(byId(33), 'Because cinematic action games align with your recent picks', 91),
    recommendationFor(byId(1), 'Because your recent watches trend sci-fi', 88),
  ],
  trending: [byId(9), byId(25), byId(33), byId(21), byId(16), byId(14)],
  upcoming: [byId(21), byId(25), byId(26), byId(14), byId(35)],
  recentlyWatched: [byId(2), byId(6), byId(17), byId(33), byId(29)],
}

export const discoverSections: DiscoverSection[] = [
  {
    kind: 'trending',
    title: 'Trending',
    subtitle: 'Hot picks across screens and launchers',
    items: [byId(9), byId(25), byId(33), byId(21), byId(6), byId(17), byId(28), byId(23)],
  },
  {
    kind: 'popular',
    title: 'Popular',
    subtitle: 'High-signal releases people keep returning to',
    items: [byId(1), byId(2), byId(33), byId(5), byId(28), byId(8), byId(10), byId(31)],
  },
  {
    kind: 'top-rated',
    title: 'Top Rated',
    subtitle: 'Highest community ratings across all media',
    items: [byId(9), byId(17), byId(25), byId(5), byId(33), byId(16), byId(28), byId(21)],
  },
  {
    kind: 'upcoming',
    title: 'Upcoming',
    subtitle: 'Near-term drops on your radar',
    items: [byId(21), byId(25), byId(26), byId(14), byId(27), byId(23), byId(35), byId(36)],
  },
  {
    kind: 'now-playing',
    title: 'Now Playing',
    subtitle: 'Freshly added movies, episodes, and game launches',
    items: [byId(3), byId(6), byId(12), byId(29), byId(33), byId(30), byId(2), byId(17)],
  },
  {
    kind: 'airing-today',
    title: 'Airing Today',
    subtitle: 'Episodes and drops available now',
    items: [byId(6), byId(10), byId(17), byId(19), byId(24), byId(22), byId(4), byId(15)],
  },
  {
    kind: 'recently-released-games',
    title: 'Recently Released Games',
    subtitle: 'New launches worth checking this month',
    items: [byId(33), byId(31), byId(29), byId(30), byId(34), byId(32)],
  },
  {
    kind: 'most-anticipated-games',
    title: 'Most Anticipated Games',
    subtitle: 'Upcoming releases with strong momentum',
    items: [byId(25), byId(26), byId(27), byId(28), byId(35), byId(36), byId(31), byId(29)],
  },
  {
    kind: 'indie-highlights',
    title: 'Indie Highlights',
    subtitle: 'Smaller teams shipping sharper ideas',
    items: [byId(30), byId(36), byId(34), byId(32), byId(28), byId(26)],
  },
]

export const mediaCatalog = catalog
