import 'dart:convert';
import 'package:crypto/crypto.dart';

import '../../../../requestCache.dart';
import 'listFiles.dart';
import 'listFilesParams.dart';
import 'listFilesResponse.dart';

class ListFilesCache extends RequestCache<ListFilesResponse> {
  String path;

  ListFilesCache({required onUpdate, required this.path}) : super(RequestCache.cacheNothing, onUpdate) {
    var bytes = utf8.encode("MarianumMobile-$path");
    String cacheName = md5.convert(bytes).toString();
    start("MarianumMobile", "wd-folder-$cacheName");
  }

  @override
  Future<ListFilesResponse> onLoad() async {
    ListFilesResponse data = await ListFiles(ListFilesParams(path)).run();
    return data;
  }

  @override
  ListFilesResponse onLocalData(String json) {
    return ListFilesResponse.fromJson(jsonDecode(json));
  }

}