/// Created by Haoyi on 2022/11/30
part of "../app_property.dart";

extension IapPropertyExtension on AppProperty {
  Future<void> saveFailedIapOrders(OrdersReport order) async {
    await setString(PropertyKeys.buildReportFailedIapOrdersKey(), json.encode(order));
  }

  Future<PropertyBundle> loadAllFailedIapOrders() async {
    try {
      return await loadValuesByTag(PropertyTags.failedOrders);
    } catch (e) {
      Log.e("error:$e");
    }
    return PropertyBundle.empty();
  }

  Future<void> removeReportSuccessOrder(PropertyKey key) async {
    remove(key);
  }

  Future<int> increaseGraceCount() async {
    final count = await getInt(PropertyKeys.subscriptionGraceCount, defValue: 0);
    await setInt(PropertyKeys.subscriptionGraceCount, count + 1);
    return count + 1;
  }

  Future<void> resetGraceCount() async {
    await setInt(PropertyKeys.subscriptionGraceCount, 0);
  }
}
