import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/chat_category_repository_impl.dart';
import 'package:im_app/domain/entities/chat_category.dart';
import 'package:im_app/domain/repositories/chat_category_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'chat_category_provider.g.dart';

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

/// 聊天分类仓储 Provider
final chatCategoryRepositoryProvider = Provider<ChatCategoryRepository>((ref) {
  return ChatCategoryRepositoryImpl(ref.watch(storageSdkProvider));
});

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

/// 监听所有聊天分类
@riverpod
Stream<List<ChatCategory>> allChatCategories(Ref ref) {
  return ref.watch(chatCategoryRepositoryProvider).watchAllChatCategories();
}

/// 监听指定聊天分类
@riverpod
Stream<ChatCategory?> chatCategory(Ref ref, int id) {
  return ref.watch(chatCategoryRepositoryProvider).watchChatCategory(id);
}
