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.operation.Purchases;
import com.atmob.voiceai.sdk.billing.operation.QueryDetails;
import com.atmob.voiceai.sdk.billing.operation.Subscription;

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 billingClient.isFeatureSupported(BillingClient.FeatureType.PRODUCT_DETAILS).getResponseCode() == BillingClient.BillingResponseCode.OK;
    }

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


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


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

}