import 'package:im_app/domain/entities/user.dart';
import 'package:im_app/domain/repositories/user_repository.dart';

/// 删除前10个用户用例
///
/// ## 职责
/// - 取前10个用户
/// - 按 uid 逐条删除
///
/// ## 数据流
/// ```
/// ViewModel
///   → DeleteUsersUseCase.execute(users)
///     → 取前10条
///     → UserRepository.deleteUser(uid) × n
///   ← 已删除的用户列表
/// ```
class DeleteUsersUseCase {
  final UserRepository _repo;

  DeleteUsersUseCase({required UserRepository userRepository})
    : _repo = userRepository;

  /// 删除前10个用户
  ///
  /// [users] 当前用户列表，取前10条删除
  /// 返回已删除的用户列表，供 ViewModel 从 UI 中移除
  Future<List<User>> execute(List<User> users) async {
    if (users.isEmpty) return [];

    final targets = users.take(10).toList();

    for (final user in targets) {
      await _repo.deleteUser(user.uid);
    }

    return targets;
  }
}
