import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/call_log_repository_impl.dart';
import 'package:im_app/domain/entities/call_log.dart';
import 'package:im_app/domain/repositories/call_log_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'call_log_provider.g.dart';

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

/// 通话记录仓储 Provider
final callLogRepositoryProvider = Provider<CallLogRepository>((ref) {
  return CallLogRepositoryImpl(ref.watch(storageSdkProvider));
});

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

/// 监听所有通话记录
@riverpod
Stream<List<CallLog>> allCallLogs(Ref ref) {
  return ref.watch(callLogRepositoryProvider).watchAllCallLogs();
}

/// 监听指定通话记录
@riverpod
Stream<CallLog?> callLog(Ref ref, String id) {
  return ref.watch(callLogRepositoryProvider).watchCallLog(id);
}
