import 'package:dio/dio.dart';

import '../../models/album.dart';
import '../../models/artist.dart';
import '../../models/page.dart';

/// Paged library browse endpoints. Distinct from LibraryApi (which
/// fetches Home + entity detail) so screens that just need a flat
/// list don't drag in detail-page providers.
class LibraryListsApi {
  LibraryListsApi(this._dio);
  final Dio _dio;

  Future<Paged<ArtistRef>> listArtists({int limit = 50, int offset = 0}) async {
    // Server mounts the artists list at /api/artists (handleListArtists),
    // not /api/library/artists. Albums use /api/library/albums for
    // historical reasons; the paths aren't symmetric.
    final r = await _dio.get<Map<String, dynamic>>(
      '/api/artists',
      queryParameters: {
        'limit': limit,
        'offset': offset,
        'sort': 'alpha',
      },
    );
    return Paged.fromJson(r.data ?? const {}, ArtistRef.fromJson);
  }

  Future<Paged<AlbumRef>> listAlbums({int limit = 50, int offset = 0}) async {
    final r = await _dio.get<Map<String, dynamic>>(
      '/api/library/albums',
      queryParameters: {'limit': limit, 'offset': offset},
    );
    return Paged.fromJson(r.data ?? const {}, AlbumRef.fromJson);
  }
}
