import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:recording_tool/core/network/offline_queue/offline_queue_manager.dart';
import 'package:recording_tool/core/network/offline_queue/offline_queue_state.dart';
import 'package:recording_tool/core/network/offline_queue/offline_queue_storage.dart';
import 'package:recording_tool/core/network/providers/network_providers.dart';
import 'package:dio/dio.dart';

final offlineQueueStorageProvider = Provider<OfflineQueueStorage>((ref) {
  return OfflineQueueStorage();
});

final offlineQueueDioProvider = Provider<Dio>((ref) {
  return Dio();
});

final offlineQueueManagerProvider = Provider<OfflineQueueManager>((ref) {
  final manager = OfflineQueueManager(
    dio: ref.watch(offlineQueueDioProvider),
    monitor: ref.watch(networkMonitorProvider),
    storage: ref.watch(offlineQueueStorageProvider),
  );
  manager.init();
  ref.onDispose(manager.dispose);
  return manager;
});

final offlineQueueStateProvider = StreamProvider<OfflineQueueState>((ref) {
  return ref.watch(offlineQueueManagerProvider).stateStream;
});
