package com.atmob.voiceai.sdk.billing;


import android.app.Activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.Purchase;
import com.atmob.voiceai.sdk.billing.bean.GPProductInfo;
import com.atmob.voiceai.sdk.billing.classify.FeatureSupported;
import com.atmob.voiceai.sdk.billing.classify.QueryPurchases;
import com.atmob.voiceai.sdk.billing.classify.QueryGoods;
import com.atmob.voiceai.sdk.billing.classify.Purchases;

import java.util.List;

import atmob.reactivex.rxjava3.core.Single;
import atmob.reactivex.rxjava3.core.SingleSource;

public class BillingStrategy {


    private static final String TAG = "BillingStrategy";

    private final BillingClient billingClient;


    public BillingStrategy(BillingClient billingClient) {
        this.billingClient = billingClient;
    }

    public boolean isSupportProductDetails() {
        return FeatureSupported.isFeatureSupported(billingClient, BillingClient.FeatureType.PRODUCT_DETAILS);
    }

    public Single<GPProductInfo> queryGoodsDetails(String productType, @NonNull String productId, @Nullable String basePlanId, @Nullable String legacyProductId) {
        return QueryGoods.queryGoodsDetails(billingClient, productType, productId, basePlanId, legacyProductId);
    }


    public Single<BillingResult> subscriptionGoods(Activity activity, Object productDetails, String basePlanId, String orderNo) {
        return Purchases.launchPurchaseGoods(billingClient, activity, productDetails, basePlanId, orderNo);
    }


    public SingleSource<List<Purchase>> queryPurchase(@BillingClient.ProductType String productType) {
        return QueryPurchases.queryPurchase(billingClient, productType);
    }

}