import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/pending_friend_request_history_repository_impl.dart';
import 'package:im_app/domain/entities/pending_friend_request_history.dart';
import 'package:im_app/domain/repositories/pending_friend_request_history_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'pending_friend_request_history_provider.g.dart';

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

final pendingFriendRequestHistoryRepositoryProvider =
    Provider<PendingFriendRequestHistoryRepository>((ref) {
      return PendingFriendRequestHistoryRepositoryImpl(
        ref.watch(storageSdkProvider),
      );
    });

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

/// 监听所有好友请求历史
@riverpod
Stream<List<PendingFriendRequestHistory>> allPendingFriendRequestHistories(
  Ref ref,
) {
  return ref.watch(pendingFriendRequestHistoryRepositoryProvider).watchAll();
}

/// 监听指定 uid 的好友请求历史
@riverpod
Stream<List<PendingFriendRequestHistory>> pendingFriendRequestHistoriesByUid(
  Ref ref,
  int uid,
) {
  return ref
      .watch(pendingFriendRequestHistoryRepositoryProvider)
      .watchByUid(uid);
}
