import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/user_request_history_repository_impl.dart';
import 'package:im_app/domain/entities/user_request_history.dart';
import 'package:im_app/domain/repositories/user_request_history_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'user_request_history_provider.g.dart';

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

final userRequestHistoryRepositoryProvider =
    Provider<UserRequestHistoryRepository>((ref) {
      return UserRequestHistoryRepositoryImpl(ref.watch(storageSdkProvider));
    });

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

/// 监听所有用户请求历史
@riverpod
Stream<List<UserRequestHistory>> allUserRequestHistories(Ref ref) {
  return ref.watch(userRequestHistoryRepositoryProvider).watchAll();
}

/// 监听指定状态的用户请求历史
@riverpod
Stream<List<UserRequestHistory>> userRequestHistoriesByStatus(
  Ref ref,
  int status,
) {
  return ref.watch(userRequestHistoryRepositoryProvider).watchByStatus(status);
}

/// 监听指定用户请求历史
@riverpod
Stream<UserRequestHistory?> userRequestHistoryById(Ref ref, int id) {
  return ref.watch(userRequestHistoryRepositoryProvider).watchById(id);
}
