package com.foxx.androidcast.commercial;

import android.content.Context;

import com.foxx.androidcast.AppPreferences;

/**
 * Gates ads, in-app purchases, and Play Store integration. All off until enabled in
 * developer settings (commercial release prep).
 */
public final class CommercialFeatures {
    private CommercialFeatures() {}

    public static boolean isAdsEnabled(Context context) {
        return AppPreferences.isDevCommercialAdsEnabled(context);
    }

    public static boolean isInAppPurchaseEnabled(Context context) {
        return AppPreferences.isDevCommercialIapEnabled(context);
    }

    public static boolean isPlayStoreIntegrationEnabled(Context context) {
        return AppPreferences.isDevCommercialPlayStoreEnabled(context);
    }

    public static boolean isAnyCommercialFeatureEnabled(Context context) {
        return isAdsEnabled(context)
                || isInAppPurchaseEnabled(context)
                || isPlayStoreIntegrationEnabled(context);
    }

    /** Lazy-init billing / ads / review helpers when flags are turned on. */
    public static void refreshFromPreferences(Context context) {
        Context app = context.getApplicationContext();
        if (isInAppPurchaseEnabled(app)) {
            InAppPurchaseCoordinator.getInstance(app).ensureInitialized();
        } else {
            InAppPurchaseCoordinator.getInstance(app).shutdown();
        }
        if (isAdsEnabled(app)) {
            InAppAdCoordinator.getInstance(app).ensureInitialized();
        } else {
            InAppAdCoordinator.getInstance(app).shutdown();
        }
        if (isPlayStoreIntegrationEnabled(app)) {
            PlayStoreIntegration.getInstance(app).ensureInitialized();
        }
    }
}
