import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:im_app/app/di/db_provider.dart';
import 'package:im_app/data/repositories/api_retry_repository_impl.dart';
import 'package:im_app/domain/entities/api_retry.dart';
import 'package:im_app/domain/repositories/api_retry_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'api_retry_provider.g.dart';

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

final apiRetryRepositoryProvider = Provider<ApiRetryRepository>((ref) {
  return ApiRetryRepositoryImpl(ref.watch(storageSdkProvider));
});

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

/// 监听所有重试任务
@riverpod
Stream<List<ApiRetry>> allApiRetries(Ref ref) {
  return ref.watch(apiRetryRepositoryProvider).watchAll();
}

/// 监听未同步的重试任务
@riverpod
Stream<List<ApiRetry>> pendingApiRetries(Ref ref) {
  return ref.watch(apiRetryRepositoryProvider).watchPending();
}
