import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/workspace_repository_impl.dart';
import 'package:im_app/domain/entities/workspace.dart';
import 'package:im_app/domain/repositories/workspace_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'workspace_provider.g.dart';

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

final workspaceRepositoryProvider = Provider<WorkspaceRepository>((ref) {
  return WorkspaceRepositoryImpl(ref.watch(storageSdkProvider));
});

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

/// 监听所有工作空间
@riverpod
Stream<List<Workspace>> allWorkspaces(Ref ref) {
  return ref.watch(workspaceRepositoryProvider).watchAll();
}

/// 监听指定工作空间
@riverpod
Stream<Workspace?> workspaceById(Ref ref, int id) {
  return ref.watch(workspaceRepositoryProvider).watchById(id);
}
