import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/favorite_repository_impl.dart';
import 'package:im_app/domain/entities/favorite.dart';
import 'package:im_app/domain/repositories/favorite_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'favorite_provider.g.dart';

// ── Repository ────────────────────────────────────────────────────────────────

/// 收藏仓储 Provider
final favoriteRepositoryProvider = Provider<FavoriteRepository>((ref) {
  return FavoriteRepositoryImpl(ref.watch(storageSdkProvider));
});

// ── Streams ───────────────────────────────────────────────────────────────────

/// 监听所有收藏
@riverpod
Stream<List<Favorite>> allFavorites(Ref ref) {
  return ref.watch(favoriteRepositoryProvider).watchAll();
}

/// 监听指定收藏
@riverpod
Stream<Favorite?> favoriteById(Ref ref, int id) {
  return ref.watch(favoriteRepositoryProvider).watchById(id);
}

/// 监听指定 parentId 的收藏
@riverpod
Stream<List<Favorite>> favoritesByParentId(Ref ref, String parentId) {
  return ref.watch(favoriteRepositoryProvider).watchByParentId(parentId);
}
