// import 'package:guru_app/controller/lifecycle_controller.dart';
// import 'package:guru_app/financial/asset/assets_store.dart';
// import 'package:guru_app/financial/iap/iap_manager.dart';
// import 'package:guru_app/financial/iap/iap_model.dart';
// import 'package:guru_app/financial/product/product_model.dart';
// import 'package:guru_app/financial/product/product_store.dart';
// import 'package:guru_app/guru_app.dart';
// import 'package:guru_utils/datetime/datetime_utils.dart';
// import 'package:guru_utils/extensions/extensions.dart';
//
// /// Created by Haoyi on 2022/4/7
//
// mixin AssetsAware on LifecycleController {
//   final BehaviorSubject<ProductStore<IapProduct>> _productStoreSubject =
//       BehaviorSubject.seeded(ProductStore());
//
//   ProductStore<IapProduct> get currentProductStore => _productStoreSubject.value;
//
//   AssetsStore<IapPurchased> get currentIapAssetStore => IapManager.instance.purchasedStore;
//
//   Stream<ProductStore<IapProduct>> get observableProductStore => _productStoreSubject.stream;
//
//   Stream<AssetsStore<IapPurchased>> get observableIapPurchased =>
//       IapManager.instance.observablePurchasedStore;
//
//   int _latestRefreshIapProductTimestamp = 0;
//
//   bool get isIapCanceled => IapManager.instance.latestIapCause == IapCause.canceled;
//
//   bool get isIapError => IapManager.instance.latestIapCause == IapCause.error;
//
//   Future restorePurchases() async {
//     return await IapManager.instance.restorePurchases();
//   }
//
//   Future clearIapAssets() async {
//     return await IapManager.instance.clearAssetRecord();
//   }
//
//   void observeIapProducts(Set<TransactionIntent> intents) {
//     addSubscription(IapManager.instance.observableProductDetails.listen((details) async {
//       final productStore = await IapManager.instance.buildProducts(intents);
//       _productStoreSubject.addEx(productStore);
//     }));
//   }
//
//   void refreshIapProducts() async {
//     final now = DateTimeUtils.currentTimeInMillis();
//     if (now - _latestRefreshIapProductTimestamp > DateTimeUtils.minuteInMillis) {
//       IapManager.instance.refreshProducts();
//       _latestRefreshIapProductTimestamp = now;
//     } else {
//       Log.w("refreshIapProducts Too Frequency!", tag: "IAP");
//     }
//   }
//
//   Future<bool> requestProduct(Product product, {String from = ""}) async {
//     if (product is IapProduct) {
//       return await IapManager.instance.buy(product);
//     } else {
//       return false;
//     }
//   }
// }
