import 'package:recording_tool/core/cache/app_storage.dart';
import 'package:recording_tool/core/cache/storage_keys.dart';
import 'package:recording_tool/core/network/offline_queue/offline_request.dart';

class OfflineQueueStorage {
  Future<List<OfflineRequest>> loadQueue() async {
    final list = AppStorage.getStringList(StorageKeys.offlineQueue);
    return list.map(OfflineRequest.decode).toList();
  }

  Future<List<OfflineRequest>> loadDead() async {
    final list = AppStorage.getStringList(StorageKeys.offlineDeadQueue);
    return list.map(OfflineRequest.decode).toList();
  }

  Future<void> saveQueue(List<OfflineRequest> list) async {
    await AppStorage.setStringList(
      StorageKeys.offlineQueue,
      list.map((item) => item.encode()).toList(),
    );
  }

  Future<void> saveDead(List<OfflineRequest> list) async {
    await AppStorage.setStringList(
      StorageKeys.offlineDeadQueue,
      list.map((item) => item.encode()).toList(),
    );
  }
}
