package com.revenuecat.purchases.google.usecase;

import I2.AbstractC0319c;
import I2.C0320d;
import I2.C0322f;
import I2.C0328l;
import android.os.Bundle;
import android.os.DeadObjectException;
import com.google.android.gms.internal.play_billing.zzam;
import com.google.android.gms.internal.play_billing.zzc;
import com.google.android.gms.internal.play_billing.zzie;
import com.revenuecat.purchases.LogHandler;
import com.revenuecat.purchases.LogLevel;
import com.revenuecat.purchases.PurchasesError;
import com.revenuecat.purchases.PurchasesErrorCode;
import com.revenuecat.purchases.common.Config;
import com.revenuecat.purchases.common.LogIntent;
import com.revenuecat.purchases.common.LogWrapperKt;
import com.revenuecat.purchases.common.caching.DeviceCache;
import com.revenuecat.purchases.strings.BillingStrings;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import kotlin.jvm.internal.o;
import kotlin.jvm.internal.p;
import w4.C3137A;

/* JADX INFO: loaded from: classes3.dex */
public final class GetBillingConfigUseCase extends BillingClientUseCase<C0322f> {
    private final DeviceCache deviceCache;
    private final J4.c onError;
    private final J4.c onReceive;
    private final J4.c withConnectedClient;

    /* JADX INFO: renamed from: com.revenuecat.purchases.google.usecase.GetBillingConfigUseCase$executeAsync$1, reason: invalid class name */
    public static final class AnonymousClass1 extends p implements J4.c {
        public AnonymousClass1() {
            super(1);
        }

        /* JADX INFO: Access modifiers changed from: private */
        public static final void invoke$lambda$1(AtomicBoolean atomicBoolean, GetBillingConfigUseCase getBillingConfigUseCase, C0328l result, C0322f c0322f) {
            o.h(result, "result");
            if (!atomicBoolean.getAndSet(true)) {
                BillingClientUseCase.processResult$default(getBillingConfigUseCase, result, c0322f, null, null, 12, null);
                return;
            }
            LogIntent logIntent = LogIntent.GOOGLE_ERROR;
            GetBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1 getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1 = new GetBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1(logIntent, result);
            switch (LogWrapperKt.WhenMappings.$EnumSwitchMapping$0[logIntent.ordinal()]) {
                case 1:
                    LogLevel logLevel = LogLevel.DEBUG;
                    LogHandler currentLogHandler = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel) <= 0) {
                        currentLogHandler.d(com.google.android.recaptcha.internal.a.j(logLevel, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 2:
                    LogWrapperKt.getCurrentLogHandler().e("[Purchases] - ERROR", (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke(), null);
                    break;
                case 3:
                    LogLevel logLevel2 = LogLevel.WARN;
                    LogHandler currentLogHandler2 = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel2) <= 0) {
                        currentLogHandler2.w(com.google.android.recaptcha.internal.a.j(logLevel2, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 4:
                    LogLevel logLevel3 = LogLevel.INFO;
                    LogHandler currentLogHandler3 = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel3) <= 0) {
                        currentLogHandler3.i(com.google.android.recaptcha.internal.a.j(logLevel3, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 5:
                    LogLevel logLevel4 = LogLevel.DEBUG;
                    LogHandler currentLogHandler4 = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel4) <= 0) {
                        currentLogHandler4.d(com.google.android.recaptcha.internal.a.j(logLevel4, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 6:
                    LogWrapperKt.getCurrentLogHandler().e("[Purchases] - ERROR", (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke(), null);
                    break;
                case 7:
                    LogLevel logLevel5 = LogLevel.INFO;
                    LogHandler currentLogHandler5 = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel5) <= 0) {
                        currentLogHandler5.i(com.google.android.recaptcha.internal.a.j(logLevel5, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 8:
                    LogLevel logLevel6 = LogLevel.DEBUG;
                    LogHandler currentLogHandler6 = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel6) <= 0) {
                        currentLogHandler6.d(com.google.android.recaptcha.internal.a.j(logLevel6, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 9:
                    LogLevel logLevel7 = LogLevel.DEBUG;
                    LogHandler currentLogHandler7 = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel7) <= 0) {
                        currentLogHandler7.d(com.google.android.recaptcha.internal.a.j(logLevel7, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 10:
                    LogLevel logLevel8 = LogLevel.WARN;
                    LogHandler currentLogHandler8 = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel8) <= 0) {
                        currentLogHandler8.w(com.google.android.recaptcha.internal.a.j(logLevel8, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 11:
                    LogLevel logLevel9 = LogLevel.WARN;
                    LogHandler currentLogHandler9 = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel9) <= 0) {
                        currentLogHandler9.w(com.google.android.recaptcha.internal.a.j(logLevel9, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 12:
                    LogWrapperKt.getCurrentLogHandler().e("[Purchases] - ERROR", (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke(), null);
                    break;
                case 13:
                    LogLevel logLevel10 = LogLevel.WARN;
                    LogHandler currentLogHandler10 = LogWrapperKt.getCurrentLogHandler();
                    if (Config.INSTANCE.getLogLevel().compareTo(logLevel10) <= 0) {
                        currentLogHandler10.w(com.google.android.recaptcha.internal.a.j(logLevel10, new StringBuilder("[Purchases] - ")), (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke());
                    }
                    break;
                case 14:
                    LogWrapperKt.getCurrentLogHandler().e("[Purchases] - ERROR", (String) getBillingConfigUseCase$executeAsync$1$invoke$lambda$1$$inlined$log$1.invoke(), null);
                    break;
            }
        }

        @Override // J4.c
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            invoke((AbstractC0319c) obj);
            return C3137A.f25453a;
        }

        public final void invoke(AbstractC0319c invoke) {
            o.h(invoke, "$this$invoke");
            final b bVar = new b(new AtomicBoolean(false), GetBillingConfigUseCase.this);
            final C0320d c0320d = (C0320d) invoke;
            if (C0320d.j(new Callable() { // from class: I2.F
                @Override // java.util.concurrent.Callable
                public final Object call() {
                    zzam zzamVar;
                    C0320d c0320d2 = c0320d;
                    com.revenuecat.purchases.google.usecase.b bVar2 = bVar;
                    c0320d2.getClass();
                    try {
                        if (!c0320d2.v()) {
                            zzc.zzn("BillingClient", "Service disconnected.");
                            zzie zzieVar = zzie.SERVICE_CONNECTION_NOT_READY;
                            C0328l c0328l = V.f2551j;
                            c0320d2.I(13, c0328l, zzieVar);
                            bVar2.a(c0328l, null);
                            return null;
                        }
                        if (!c0320d2.f2611v) {
                            zzc.zzn("BillingClient", "Current client doesn't support get billing config.");
                            zzie zzieVar2 = zzie.GET_BILLING_CONFIG_NOT_SUPPORTED;
                            C0328l c0328l2 = V.f2564x;
                            c0320d2.I(13, c0328l2, zzieVar2);
                            bVar2.a(c0328l2, null);
                            return null;
                        }
                        synchronized (c0320d2.f2591a) {
                            zzamVar = c0320d2.f2599i;
                        }
                        if (zzamVar == null) {
                            c0320d2.m(bVar2, V.f2551j, zzie.SERVICE_RESET_TO_NULL, null);
                            return null;
                        }
                        String packageName = c0320d2.f2597g.getPackageName();
                        String str = c0320d2.f2593c;
                        String str2 = c0320d2.f2594d;
                        long jLongValue = c0320d2.f2589F.longValue();
                        int i6 = zzc.zza;
                        Bundle bundle = new Bundle();
                        zzc.zzc(bundle, str, str2, jLongValue);
                        zzamVar.zzn(18, packageName, bundle, new M(bVar2, c0320d2.f2598h, c0320d2.f2602m));
                        return null;
                    } catch (DeadObjectException e6) {
                        c0320d2.m(bVar2, V.f2551j, zzie.GET_BILLING_CONFIG_SERVICE_CALL_EXCEPTION, e6);
                        return null;
                    } catch (Exception e7) {
                        c0320d2.m(bVar2, V.f2549h, zzie.GET_BILLING_CONFIG_SERVICE_CALL_EXCEPTION, e7);
                        return null;
                    }
                }
            }, 30000L, new C1.a(4, c0320d, bVar), c0320d.z(), c0320d.i()) == null) {
                C0328l c0328lC = c0320d.C();
                c0320d.I(13, c0328lC, zzie.MISSING_RESULT_FROM_EXECUTE_ASYNC);
                bVar.a(c0328lC, null);
            }
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public GetBillingConfigUseCase(GetBillingConfigUseCaseParams useCaseParams, DeviceCache deviceCache, J4.c onReceive, J4.c onError, J4.c withConnectedClient, J4.e executeRequestOnUIThread) {
        super(useCaseParams, onError, executeRequestOnUIThread);
        o.h(useCaseParams, "useCaseParams");
        o.h(deviceCache, "deviceCache");
        o.h(onReceive, "onReceive");
        o.h(onError, "onError");
        o.h(withConnectedClient, "withConnectedClient");
        o.h(executeRequestOnUIThread, "executeRequestOnUIThread");
        this.deviceCache = deviceCache;
        this.onReceive = onReceive;
        this.onError = onError;
        this.withConnectedClient = withConnectedClient;
    }

    @Override // com.revenuecat.purchases.google.usecase.BillingClientUseCase
    public void executeAsync() {
        this.withConnectedClient.invoke(new AnonymousClass1());
    }

    public final DeviceCache getDeviceCache() {
        return this.deviceCache;
    }

    @Override // com.revenuecat.purchases.google.usecase.BillingClientUseCase
    public String getErrorMessage() {
        return "Error getting billing config";
    }

    public final J4.c getOnError() {
        return this.onError;
    }

    public final J4.c getOnReceive() {
        return this.onReceive;
    }

    public final J4.c getWithConnectedClient() {
        return this.withConnectedClient;
    }

    @Override // com.revenuecat.purchases.google.usecase.BillingClientUseCase
    public void onOk(C0322f c0322f) {
        if (c0322f == null) {
            this.onError.invoke(new PurchasesError(PurchasesErrorCode.StoreProblemError, BillingStrings.BILLING_CONFIG_NULL_ON_SUCCESS));
            return;
        }
        DeviceCache deviceCache = this.deviceCache;
        String str = c0322f.f2616a;
        o.g(str, "received.countryCode");
        deviceCache.setStorefront$purchases_defaultsBc8Release(str);
        this.onReceive.invoke(c0322f);
    }
}
