import 'folder_album_filter.dart';
import 'package:aves/model/db/folder_stats.dart';
import 'package:aves/model/entry/entry.dart';

/// Costruisce FolderAlbumFilter da folderMap + entriesMap
class FolderAlbumSource {
  final Map<String, FolderStats> folderMap;
  final Map<int, AvesEntry> entriesMap;

  FolderAlbumSource({
    required this.folderMap,
    required this.entriesMap,
  });

  /// Ritorna tutti gli album come FolderAlbumFilter
  List<FolderAlbumFilter> get allAlbums {
    return folderMap.values.map((f) {
      return FolderAlbumFilter(
        path: f.path,
        displayName: f.displayName,
        isRemote: f.isRemote == 1, // FIX: int → bool
      );
    }).toList();
  }

  /// Sorting semplice: per nome
  List<FolderAlbumFilter> sortedAlbums(dynamic sortFactor) {
    final list = allAlbums;
    list.sort((a, b) => a.displayName.toLowerCase().compareTo(b.displayName.toLowerCase()));
    return list;
  }

  /// Grouping disattivato (AlbumPage patchata non lo usa)
  Map<String, List<FolderAlbumFilter>> groupedAlbums(dynamic groupFactor) {
    return {
      'all': sortedAlbums(null),
    };
  }
}
