import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/chat_repository_impl.dart';
import 'package:im_app/domain/entities/chat.dart';
import 'package:im_app/domain/repositories/chat_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'chat_provider.g.dart';

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

/// 聊天仓储 Provider
final chatRepositoryProvider = Provider<ChatRepository>((ref) {
  return ChatRepositoryImpl(ref.watch(storageSdkProvider));
});

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

/// 监听所有聊天
@riverpod
Stream<List<Chat>> allChats(Ref ref) {
  return ref.watch(chatRepositoryProvider).watchAllChats();
}

/// 监听指定聊天
@riverpod
Stream<Chat?> chat(Ref ref, int id) {
  return ref.watch(chatRepositoryProvider).watchChat(id);
}
