//package com.base.filerecoveryrecyclebin.billing
//
//import android.app.Application
//import android.util.Log
//import androidx.lifecycle.AndroidViewModel
//import com.base.filerecoveryrecyclebin.MyApplication
//import com.base.filerecoveryrecyclebin.bean.BiliConstants
//import com.base.filerecoveryrecyclebin.utils.SingleLiveEvent
//
//class BillingViewModel(val application: Application) : AndroidViewModel(application) {
//
//    private val TAG = "BillingViewModel"
//
//
//    private val purchases = (application as MyApplication).billingClientLifecycle.subscriptionPurchases
//    private val basicSubProductWithProductDetails =
//        (application as MyApplication).billingClientLifecycle.basicSubProductWithProductDetails
//    private val premiumSubProductWithProductDetails =
//        (application as MyApplication).billingClientLifecycle.premiumSubProductWithProductDetails
//
//    val openPlayStoreSubscriptionsEvent = SingleLiveEvent<String>()
//
//    /**
//     * Open the Play Store subscription center. If the user has exactly one product,
//     * then open the deeplink to the specific product.
//     */
//    fun openPlayStoreSubscriptions() {
//        val hasBasic = deviceHasGooglePlaySubscription(purchases.value, BiliConstants.BASIC_PRODUCT)
//        val hasPremium = deviceHasGooglePlaySubscription(purchases.value, BiliConstants.BASIC_PRODUCT)
//        Log.d(TAG, "hasBasic: $hasBasic, hasPremium: $hasPremium")
//        when {
//            hasBasic && !hasPremium -> {
//                // If we just have a basic subscription, open the basic Product.
//                openPlayStoreSubscriptionsEvent.postValue(BiliConstants.BASIC_PRODUCT)
//            }
//
//            !hasBasic && hasPremium -> {
//                // If we just have a premium subscription, open the premium Product.
//                openPlayStoreSubscriptionsEvent.postValue(BiliConstants.PREMIUM_PRODUCT)
//            }
//
//            else -> {
//                // If we do not have an active subscription,
//                // or if we have multiple subscriptions, open the default subscription center.
//                openPlayStoreSubscriptionsEvent.call()
//            }
//        }
//    }
//}