// Mirrors the server's Page envelope used by paged endpoints // (/api/search, /api/library/artists, /api/library/albums, // /api/library/history, /api/me/likes/*). // // Wire shape from internal/api/types.go Page[T]: // { items: T[], total: int, limit: int, offset: int } // // Dart generics can't auto-infer T from JSON, so callers pass an // itemFromJson function alongside the raw map. Parse logic stays in // each entity's own fromJson; this class only handles the envelope. class Page { const Page({ required this.items, required this.total, required this.limit, required this.offset, }); final List items; final int total; final int limit; final int offset; factory Page.fromJson( Map j, T Function(Map) itemFromJson, ) { final raw = (j['items'] as List?) ?? const []; return Page( items: raw .map((e) => itemFromJson((e as Map).cast())) .toList(growable: false), total: (j['total'] as num?)?.toInt() ?? 0, limit: (j['limit'] as num?)?.toInt() ?? 0, offset: (j['offset'] as num?)?.toInt() ?? 0, ); } /// Convenience for endpoints that always return the first page or /// when the caller just wants the items. bool get hasMore => offset + items.length < total; }