import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/favorite_detail_repository_impl.dart';
import 'package:im_app/domain/repositories/favorite_detail_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:im_app/domain/entities/favorite_detail.dart';

part 'favorite_detail_provider.g.dart';

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

/// 收藏详情仓储 Provider
final favoriteDetailRepositoryProvider = Provider<FavoriteDetailRepository>((
  ref,
) {
  return FavoriteDetailRepositoryImpl(ref.watch(storageSdkProvider));
});

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

/// 监听所有收藏详情
@riverpod
Stream<List<FavoriteDetail>> allFavoriteDetails(Ref ref) {
  return ref.watch(favoriteDetailRepositoryProvider).watchAll();
}

/// 监听指定 relatedId 的收藏详情
@riverpod
Stream<List<FavoriteDetail>> favoriteDetailsByRelatedId(
  Ref ref,
  String relatedId,
) {
  return ref
      .watch(favoriteDetailRepositoryProvider)
      .watchByRelatedId(relatedId);
}
