package com.revenuecat.purchases.ui.revenuecatui.data.testdata;

import A4.d;
import B4.a;
import C4.c;
import C4.e;
import C4.j;
import E3.v;
import V4.C;
import V4.E;
import Y4.H;
import Y4.J;
import Y4.O;
import Y4.a0;
import a0.I;
import android.app.Activity;
import androidx.compose.runtime.MutableState;
import androidx.compose.runtime.SnapshotStateKt__SnapshotStateKt;
import androidx.compose.runtime.State;
import androidx.compose.runtime.internal.StabilityInferred;
import androidx.lifecycle.X;
import androidx.lifecycle.b0;
import com.revenuecat.purchases.Offering;
import com.revenuecat.purchases.Package;
import com.revenuecat.purchases.PurchasesError;
import com.revenuecat.purchases.paywalls.events.ExitOfferType;
import com.revenuecat.purchases.ui.revenuecatui.PaywallMode;
import com.revenuecat.purchases.ui.revenuecatui.PaywallOptions;
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallResult;
import com.revenuecat.purchases.ui.revenuecatui.components.PaywallAction;
import com.revenuecat.purchases.ui.revenuecatui.data.MockPurchasesType;
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallState;
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallStateKt;
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel;
import com.revenuecat.purchases.ui.revenuecatui.data.processed.TemplateConfiguration;
import com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableDataProvider;
import com.revenuecat.purchases.ui.revenuecatui.data.testdata.TestData;
import com.revenuecat.purchases.ui.revenuecatui.helpers.OfferingToStateMapperKt;
import com.revenuecat.purchases.ui.revenuecatui.helpers.PaywallValidationResult;
import com.revenuecat.purchases.ui.revenuecatui.helpers.PaywallWarning;
import com.revenuecat.purchases.ui.revenuecatui.helpers.ResolvedOffer;
import com.revenuecat.purchases.ui.revenuecatui.helpers.ResourceProvider;
import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.h;
import kotlin.jvm.internal.o;
import m3.AbstractC2467b;
import w4.C3137A;
import w4.k;

/* JADX INFO: loaded from: classes3.dex */
@StabilityInferred(parameters = 1)
public final class MockViewModel extends b0 implements PaywallViewModel {
    public static final int $stable = 0;
    private static final Companion Companion = new Companion(null);
    private static final long MILLIS_2025_01_25 = 1737763200000L;

    @Deprecated
    public static final long fakePurchaseDelayMillis = 2000;
    private final MutableState<PurchasesError> _actionError;
    private final MutableState<Boolean> _actionInProgress;
    private final H _state;
    private final boolean allowsPurchases;
    private int clearActionErrorCallCount;
    private int closePaywallCallCount;
    private int getWebCheckoutUrlCallCount;
    private List<PaywallAction.External.LaunchWebCheckout> getWebCheckoutUrlParams;
    private int handlePackagePurchaseCount;
    private List<k> handlePackagePurchaseParams;
    private int handleRestorePurchasesCallCount;
    private int invalidateCustomerInfoCacheCallCount;
    private int preloadExitOfferingCallCount;
    private final State<Offering> preloadedExitOffering;
    private final State<Boolean> purchaseCompleted;
    private int purchaseSelectedPackageCallCount;
    private List<String> purchaseSelectedPackageIdentifiers;
    private List<Activity> purchaseSelectedPackageParams;
    private int refreshStateIfColorsChangedCallCount;
    private int refreshStateIfLocaleChangedCallCount;
    private int restorePurchasesCallCount;
    private int selectPackageCallCount;
    private List<TemplateConfiguration.PackageInfo> selectPackageCallParams;
    private final boolean shouldErrorOnUnsupportedMethods;
    private int trackExitOfferCallCount;
    private List<k> trackExitOfferParams;
    private int trackPaywallImpressionIfNeededCallCount;
    private int updateOptionsCallCount;
    private List<PaywallOptions> updateOptionsParams;

    public static final class Companion {
        public /* synthetic */ Companion(h hVar) {
            this();
        }

        private Companion() {
        }
    }

    /* JADX INFO: renamed from: com.revenuecat.purchases.ui.revenuecatui.data.testdata.MockViewModel$awaitSimulateActionInProgress$1, reason: invalid class name */
    @e(c = "com.revenuecat.purchases.ui.revenuecatui.data.testdata.MockViewModel", f = "TestData.kt", l = {699}, m = "awaitSimulateActionInProgress")
    public static final class AnonymousClass1 extends c {
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public AnonymousClass1(d dVar) {
            super(dVar);
        }

        @Override // C4.a
        public final Object invokeSuspend(Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return MockViewModel.this.awaitSimulateActionInProgress(this);
        }
    }

    /* JADX INFO: renamed from: com.revenuecat.purchases.ui.revenuecatui.data.testdata.MockViewModel$simulateActionInProgress$1, reason: invalid class name and case insensitive filesystem */
    @e(c = "com.revenuecat.purchases.ui.revenuecatui.data.testdata.MockViewModel$simulateActionInProgress$1", f = "TestData.kt", l = {693}, m = "invokeSuspend")
    public static final class C17261 extends j implements J4.e {
        int label;

        public C17261(d dVar) {
            super(2, dVar);
        }

        @Override // C4.a
        public final d create(Object obj, d dVar) {
            return MockViewModel.this.new C17261(dVar);
        }

        @Override // J4.e
        public final Object invoke(C c6, d dVar) {
            return ((C17261) create(c6, dVar)).invokeSuspend(C3137A.f25453a);
        }

        @Override // C4.a
        public final Object invokeSuspend(Object obj) {
            a aVar = a.f492a;
            int i6 = this.label;
            if (i6 == 0) {
                AbstractC2467b.l(obj);
                MockViewModel mockViewModel = MockViewModel.this;
                this.label = 1;
                if (mockViewModel.awaitSimulateActionInProgress(this) == aVar) {
                    return aVar;
                }
            } else {
                if (i6 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                AbstractC2467b.l(obj);
            }
            return C3137A.f25453a;
        }
    }

    public /* synthetic */ MockViewModel(PaywallMode paywallMode, Offering offering, PaywallWarning paywallWarning, boolean z6, boolean z7, int i6, h hVar) {
        this((i6 & 1) != 0 ? PaywallMode.Companion.getDefault() : paywallMode, offering, (i6 & 4) != 0 ? null : paywallWarning, (i6 & 8) != 0 ? false : z6, (i6 & 16) != 0 ? true : z7);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object awaitSimulateActionInProgress(d dVar) {
        AnonymousClass1 anonymousClass1;
        MockViewModel mockViewModel;
        if (dVar instanceof AnonymousClass1) {
            anonymousClass1 = (AnonymousClass1) dVar;
            int i6 = anonymousClass1.label;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                anonymousClass1.label = i6 - Integer.MIN_VALUE;
            } else {
                anonymousClass1 = new AnonymousClass1(dVar);
            }
        }
        Object obj = anonymousClass1.result;
        a aVar = a.f492a;
        int i7 = anonymousClass1.label;
        if (i7 == 0) {
            AbstractC2467b.l(obj);
            this._actionInProgress.setValue(Boolean.TRUE);
            anonymousClass1.L$0 = this;
            anonymousClass1.label = 1;
            if (E.l(2000L, anonymousClass1) == aVar) {
                return aVar;
            }
            mockViewModel = this;
        } else {
            if (i7 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            mockViewModel = (MockViewModel) anonymousClass1.L$0;
            AbstractC2467b.l(obj);
        }
        mockViewModel._actionInProgress.setValue(Boolean.FALSE);
        return C3137A.f25453a;
    }

    private final void simulateActionInProgress() {
        E.y(X.h(this), null, null, new C17261(null), 3);
    }

    private final void unsupportedMethod(String str) {
        if (this.shouldErrorOnUnsupportedMethods) {
            throw new IllegalStateException(str.toString());
        }
    }

    public static /* synthetic */ void unsupportedMethod$default(MockViewModel mockViewModel, String str, int i6, Object obj) {
        if ((i6 & 1) != 0) {
            str = "Not supported";
        }
        mockViewModel.unsupportedMethod(str);
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void clearActionError() {
        this.clearActionErrorCallCount++;
        this._actionError.setValue(null);
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void closePaywall(PaywallResult paywallResult) {
        this.closePaywallCallCount++;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public State<PurchasesError> getActionError() {
        return this._actionError;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public State<Boolean> getActionInProgress() {
        return this._actionInProgress;
    }

    public final int getClearActionErrorCallCount() {
        return this.clearActionErrorCallCount;
    }

    public final int getClosePaywallCallCount() {
        return this.closePaywallCallCount;
    }

    public final int getGetWebCheckoutUrlCallCount() {
        return this.getWebCheckoutUrlCallCount;
    }

    public final List<PaywallAction.External.LaunchWebCheckout> getGetWebCheckoutUrlParams() {
        return this.getWebCheckoutUrlParams;
    }

    public final int getHandlePackagePurchaseCount() {
        return this.handlePackagePurchaseCount;
    }

    public final List<k> getHandlePackagePurchaseParams() {
        return this.handlePackagePurchaseParams;
    }

    public final int getHandleRestorePurchasesCallCount() {
        return this.handleRestorePurchasesCallCount;
    }

    public final int getInvalidateCustomerInfoCacheCallCount() {
        return this.invalidateCustomerInfoCacheCallCount;
    }

    public final int getPreloadExitOfferingCallCount() {
        return this.preloadExitOfferingCallCount;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public State<Offering> getPreloadedExitOffering() {
        return this.preloadedExitOffering;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public State<Boolean> getPurchaseCompleted() {
        return this.purchaseCompleted;
    }

    public final int getPurchaseSelectedPackageCallCount() {
        return this.purchaseSelectedPackageCallCount;
    }

    public final List<String> getPurchaseSelectedPackageIdentifiers() {
        return this.purchaseSelectedPackageIdentifiers;
    }

    public final List<Activity> getPurchaseSelectedPackageParams() {
        return this.purchaseSelectedPackageParams;
    }

    public final int getRefreshStateIfColorsChangedCallCount() {
        return this.refreshStateIfColorsChangedCallCount;
    }

    public final int getRefreshStateIfLocaleChangedCallCount() {
        return this.refreshStateIfLocaleChangedCallCount;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public ResourceProvider getResourceProvider() {
        return new MockResourceProvider(null, null, null, null, null, 31, null);
    }

    public final int getRestorePurchasesCallCount() {
        return this.restorePurchasesCallCount;
    }

    public final int getSelectPackageCallCount() {
        return this.selectPackageCallCount;
    }

    public final List<TemplateConfiguration.PackageInfo> getSelectPackageCallParams() {
        return this.selectPackageCallParams;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public a0 getState() {
        return new J(this._state);
    }

    public final int getTrackExitOfferCallCount() {
        return this.trackExitOfferCallCount;
    }

    public final List<k> getTrackExitOfferParams() {
        return this.trackExitOfferParams;
    }

    public final int getTrackPaywallImpressionIfNeededCallCount() {
        return this.trackPaywallImpressionIfNeededCallCount;
    }

    public final int getUpdateOptionsCallCount() {
        return this.updateOptionsCallCount;
    }

    public final List<PaywallOptions> getUpdateOptionsParams() {
        return this.updateOptionsParams;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public String getWebCheckoutUrl(PaywallAction.External.LaunchWebCheckout launchWebCheckout) {
        o.h(launchWebCheckout, "launchWebCheckout");
        this.getWebCheckoutUrlCallCount++;
        this.getWebCheckoutUrlParams.add(launchWebCheckout);
        return null;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public Object handlePackagePurchase(Activity activity, Package r22, ResolvedOffer resolvedOffer, d dVar) {
        this.handlePackagePurchaseCount++;
        this.handlePackagePurchaseParams.add(new k(activity, r22));
        if (this.allowsPurchases) {
            simulateActionInProgress();
        } else {
            unsupportedMethod("Can't purchase mock view model");
        }
        return C3137A.f25453a;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public Object handleRestorePurchases(d dVar) {
        this.handleRestorePurchasesCallCount++;
        if (this.allowsPurchases) {
            simulateActionInProgress();
        } else {
            unsupportedMethod("Can't restore purchases");
        }
        return C3137A.f25453a;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void invalidateCustomerInfoCache() {
        this.invalidateCustomerInfoCacheCallCount++;
    }

    public final PaywallState.Loaded.Legacy loadedLegacyState() {
        return PaywallStateKt.loadedLegacy((PaywallState) getState().getValue());
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void preloadExitOffering() {
        this.preloadExitOfferingCallCount++;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void purchaseSelectedPackage(Activity activity) {
        MutableState<TemplateConfiguration.PackageInfo> selectedPackage;
        TemplateConfiguration.PackageInfo value;
        Package rcPackage;
        this.purchaseSelectedPackageCallCount++;
        this.purchaseSelectedPackageParams.add(activity);
        List<String> list = this.purchaseSelectedPackageIdentifiers;
        PaywallState.Loaded.Legacy legacyLoadedLegacyState = loadedLegacyState();
        list.add((legacyLoadedLegacyState == null || (selectedPackage = legacyLoadedLegacyState.getSelectedPackage()) == null || (value = selectedPackage.getValue()) == null || (rcPackage = value.getRcPackage()) == null) ? null : rcPackage.getIdentifier());
        if (this.allowsPurchases) {
            simulateActionInProgress();
        } else {
            unsupportedMethod("Can't purchase mock view model");
        }
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void refreshStateIfColorsChanged(I colorScheme, boolean z6) {
        o.h(colorScheme, "colorScheme");
        this.refreshStateIfColorsChangedCallCount++;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void refreshStateIfLocaleChanged() {
        this.refreshStateIfLocaleChangedCallCount++;
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void restorePurchases() {
        this.restorePurchasesCallCount++;
        if (this.allowsPurchases) {
            simulateActionInProgress();
        } else {
            unsupportedMethod("Can't restore purchases");
        }
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void selectPackage(TemplateConfiguration.PackageInfo packageToSelect) {
        C3137A c3137a;
        o.h(packageToSelect, "packageToSelect");
        this.selectPackageCallCount++;
        this.selectPackageCallParams.add(packageToSelect);
        PaywallState.Loaded.Legacy legacyLoadedLegacyState = loadedLegacyState();
        if (legacyLoadedLegacyState != null) {
            legacyLoadedLegacyState.selectPackage(packageToSelect);
            c3137a = C3137A.f25453a;
        } else {
            c3137a = null;
        }
        if (c3137a == null) {
            unsupportedMethod$default(this, null, 1, null);
        }
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void trackExitOffer(ExitOfferType exitOfferType, String exitOfferingIdentifier) {
        o.h(exitOfferType, "exitOfferType");
        o.h(exitOfferingIdentifier, "exitOfferingIdentifier");
        this.trackExitOfferCallCount++;
        this.trackExitOfferParams.add(new k(exitOfferType, exitOfferingIdentifier));
    }

    @Override // com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
    public void trackPaywallImpressionIfNeeded() {
        this.trackPaywallImpressionIfNeededCallCount++;
    }

    public final void updateOptions(PaywallOptions options) {
        o.h(options, "options");
        this.updateOptionsCallCount++;
        this.updateOptionsParams.add(options);
    }

    public MockViewModel(PaywallMode mode, Offering offering, PaywallWarning paywallWarning, boolean z6, boolean z7) {
        Object componentsPaywallState$default;
        o.h(mode, "mode");
        o.h(offering, "offering");
        this.allowsPurchases = z6;
        this.shouldErrorOnUnsupportedMethods = z7;
        Boolean bool = Boolean.FALSE;
        this.purchaseCompleted = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(bool, null, 2, null);
        this.preloadedExitOffering = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(null, null, 2, null);
        PaywallValidationResult paywallValidationResultValidatedPaywall = OfferingToStateMapperKt.validatedPaywall(offering, TestData.Constants.INSTANCE.getCurrentColorScheme(), getResourceProvider());
        if (paywallValidationResultValidatedPaywall instanceof PaywallValidationResult.Legacy) {
            PaywallValidationResult.Legacy legacy = (PaywallValidationResult.Legacy) paywallValidationResultValidatedPaywall;
            componentsPaywallState$default = OfferingToStateMapperKt.toLegacyPaywallState(offering, new VariableDataProvider(getResourceProvider(), false, 2, null), mode, legacy.getDisplayablePaywall(), legacy.getTemplate(), false, "US", paywallWarning);
        } else if (paywallValidationResultValidatedPaywall instanceof PaywallValidationResult.Components) {
            componentsPaywallState$default = OfferingToStateMapperKt.toComponentsPaywallState$default(offering, (PaywallValidationResult.Components) paywallValidationResultValidatedPaywall, null, MockViewModel$_state$1.INSTANCE, new MockPurchasesType(null, null, null, null, 15, null), null, null, 48, null);
        } else {
            throw new v();
        }
        this._state = O.c(componentsPaywallState$default);
        this._actionInProgress = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(bool, null, 2, null);
        this._actionError = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(null, null, 2, null);
        this.trackExitOfferParams = new ArrayList();
        this.selectPackageCallParams = new ArrayList();
        this.getWebCheckoutUrlParams = new ArrayList();
        this.purchaseSelectedPackageParams = new ArrayList();
        this.purchaseSelectedPackageIdentifiers = new ArrayList();
        this.handlePackagePurchaseParams = new ArrayList();
        this.updateOptionsParams = new ArrayList();
    }
}
