package com.revenuecat.purchases;

import android.app.Application;
import android.content.Context;
import android.os.Handler;
import com.revenuecat.purchases.amazon.AmazonBilling;
import com.revenuecat.purchases.common.Backend;
import com.revenuecat.purchases.common.BackendHelper;
import com.revenuecat.purchases.common.BillingAbstract;
import com.revenuecat.purchases.common.LogWrapperKt;
import com.revenuecat.purchases.common.caching.DeviceCache;
import com.revenuecat.purchases.common.diagnostics.DiagnosticsTracker;
import com.revenuecat.purchases.galaxy.GalaxyBillingMode;
import com.revenuecat.purchases.galaxy.GalaxyBillingWrapperFactory;
import com.revenuecat.purchases.google.BillingWrapper;
import com.revenuecat.purchases.google.history.PurchaseHistoryManager;
import com.revenuecat.purchases.simulatedstore.SimulatedStoreBillingWrapper;
import kotlin.jvm.internal.o;

/* JADX INFO: loaded from: classes3.dex */
public final class BillingFactory {
    public static final BillingFactory INSTANCE = new BillingFactory();

    public /* synthetic */ class WhenMappings {
        public static final /* synthetic */ int[] $EnumSwitchMapping$0;

        static {
            int[] iArr = new int[Store.values().length];
            try {
                iArr[Store.TEST_STORE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[Store.PLAY_STORE.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[Store.AMAZON.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[Store.GALAXY.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            $EnumSwitchMapping$0 = iArr;
        }
    }

    private BillingFactory() {
    }

    public final BillingAbstract createBilling(Store store, Application application, BackendHelper backendHelper, DeviceCache cache, boolean z6, DiagnosticsTracker diagnosticsTracker, PurchasesStateProvider stateProvider, boolean z7, GalaxyBillingMode galaxyBillingMode, Backend backend) {
        o.h(store, "store");
        o.h(application, "application");
        o.h(backendHelper, "backendHelper");
        o.h(cache, "cache");
        o.h(stateProvider, "stateProvider");
        o.h(galaxyBillingMode, "galaxyBillingMode");
        o.h(backend, "backend");
        int i6 = WhenMappings.$EnumSwitchMapping$0[store.ordinal()];
        if (i6 == 1) {
            return new SimulatedStoreBillingWrapper(cache, new Handler(application.getMainLooper()), stateProvider, backend, null, 16, null);
        }
        if (i6 == 2) {
            return new BillingWrapper(new BillingWrapper.ClientFactory(application, z7), new Handler(application.getMainLooper()), cache, diagnosticsTracker, stateProvider, new PurchaseHistoryManager(application), null, null, false, 448, null);
        }
        if (i6 == 3) {
            try {
                Context applicationContext = application.getApplicationContext();
                o.g(applicationContext, "application.applicationContext");
                return new AmazonBilling(applicationContext, cache, z6, new Handler(application.getMainLooper()), backendHelper, stateProvider, diagnosticsTracker);
            } catch (NoClassDefFoundError e6) {
                LogWrapperKt.getCurrentLogHandler().e("[Purchases] - ERROR", "Make sure purchases-amazon is added as dependency", e6);
                throw e6;
            }
        }
        if (i6 == 4) {
            try {
                GalaxyBillingWrapperFactory galaxyBillingWrapperFactory = GalaxyBillingWrapperFactory.INSTANCE;
                Context applicationContext2 = application.getApplicationContext();
                o.g(applicationContext2, "application.applicationContext");
                return galaxyBillingWrapperFactory.createGalaxyBillingWrapper(stateProvider, applicationContext2, galaxyBillingMode, cache);
            } catch (NoClassDefFoundError e7) {
                LogWrapperKt.getCurrentLogHandler().e("[Purchases] - ERROR", "Make sure purchases-galaxy is added as dependency", e7);
                throw e7;
            }
        }
        LogWrapperKt.getCurrentLogHandler().e("[Purchases] - ERROR", "Incompatible store (" + store + ") used", null);
        throw new IllegalArgumentException("Couldn't configure SDK. Incompatible store (" + store + ") used");
    }
}
