import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/tag_repository_impl.dart';
import 'package:im_app/domain/entities/tag.dart';
import 'package:im_app/domain/repositories/tag_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'tag_provider.g.dart';

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

final tagRepositoryProvider = Provider<TagRepository>((ref) {
  return TagRepositoryImpl(ref.watch(storageSdkProvider));
});

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

/// 监听所有标签
@riverpod
Stream<List<Tag>> allTags(Ref ref) {
  return ref.watch(tagRepositoryProvider).watchAll();
}

/// 监听指定 uid 的标签
@riverpod
Stream<List<Tag>> tagsByUid(Ref ref, int uid) {
  return ref.watch(tagRepositoryProvider).watchByUid(uid);
}

/// 监听指定类型的标签
@riverpod
Stream<List<Tag>> tagsByType(Ref ref, int type) {
  return ref.watch(tagRepositoryProvider).watchByType(type);
}

/// 监听指定标签
@riverpod
Stream<Tag?> tagById(Ref ref, int id) {
  return ref.watch(tagRepositoryProvider).watchById(id);
}
