import 'dart:convert';

import '../requestCache.dart';
import 'getHolidays.dart';
import 'getHolidaysResponse.dart';

class GetHolidaysCache extends RequestCache<GetHolidaysResponse> {
  GetHolidaysCache({onUpdate, renew}) : super(RequestCache.cacheDay, onUpdate, renew: renew) {
    start("MarianumMobile", "state-holidays");
  }

  @override
  GetHolidaysResponse onLocalData(String json) {
    List<dynamic> parsedListJson = jsonDecode(json)['data'];
    return GetHolidaysResponse(
        List<GetHolidaysResponseObject>.from(
            parsedListJson.map<GetHolidaysResponseObject>(
                    (dynamic i) => GetHolidaysResponseObject.fromJson(i)
            )
        )
    );
  }

  @override
  Future<GetHolidaysResponse> onLoad() {
    return GetHolidays().query();
  }
}