/// Mirrors internal/api/types.go HomeIndexPayload. Five flat slices of
/// entity ID strings — the per-item rendering variant of HomeData.
/// Section name implies entity type; no per-entry type tag is needed.
///
/// Slices are non-null after fromJson so callers can branch on `length`
/// instead of dealing with null sections.
class HomeIndex {
  const HomeIndex({
    required this.recentlyAddedAlbums,
    required this.rediscoverAlbums,
    required this.rediscoverArtists,
    required this.mostPlayedTracks,
    required this.lastPlayedArtists,
  });

  final List<String> recentlyAddedAlbums;
  final List<String> rediscoverAlbums;
  final List<String> rediscoverArtists;
  final List<String> mostPlayedTracks;
  final List<String> lastPlayedArtists;

  static const empty = HomeIndex(
    recentlyAddedAlbums: [],
    rediscoverAlbums: [],
    rediscoverArtists: [],
    mostPlayedTracks: [],
    lastPlayedArtists: [],
  );

  factory HomeIndex.fromJson(Map<String, dynamic> j) {
    List<String> ids(String key) =>
        ((j[key] as List?) ?? const []).map((e) => e.toString()).toList();
    return HomeIndex(
      recentlyAddedAlbums: ids('recently_added_albums'),
      rediscoverAlbums: ids('rediscover_albums'),
      rediscoverArtists: ids('rediscover_artists'),
      mostPlayedTracks: ids('most_played_tracks'),
      lastPlayedArtists: ids('last_played_artists'),
    );
  }
}
