import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/group_repository_impl.dart';
import 'package:im_app/domain/entities/group.dart';
import 'package:im_app/domain/repositories/group_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'group_provider.g.dart';

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

/// 群组仓储 Provider
final groupRepositoryProvider = Provider<GroupRepository>((ref) {
  return GroupRepositoryImpl(ref.watch(storageSdkProvider));
});

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

/// 监听所有群组
@riverpod
Stream<List<Group>> allGroups(Ref ref) {
  return ref.watch(groupRepositoryProvider).watchAll();
}

/// 监听指定群组
@riverpod
Stream<Group?> groupById(Ref ref, int id) {
  return ref.watch(groupRepositoryProvider).watchById(id);
}
