// Mirrors internal/api/types.go ArtistRef and web/src/lib/api/types.ts.
//
// `cover_url` is the server's field name (NOT cover_art_url). Server emits
// "" when the artist has no representative album cover, so we keep it
// non-null here and let UI code branch on isEmpty. `sort_name` and
// `album_count` are exposed by the server contract; we accept their
// absence defensively (older fixtures, partial mocks).
class ArtistRef {
  const ArtistRef({
    required this.id,
    required this.name,
    this.sortName = '',
    this.albumCount = 0,
    this.coverUrl = '',
  });

  final String id;
  final String name;
  final String sortName;
  final int albumCount;
  final String coverUrl;

  factory ArtistRef.fromJson(Map<String, dynamic> j) => ArtistRef(
        id: j['id'] as String,
        name: j['name'] as String,
        sortName: j['sort_name'] as String? ?? '',
        albumCount: (j['album_count'] as num?)?.toInt() ?? 0,
        coverUrl: j['cover_url'] as String? ?? '',
      );
}
