package com.strmr.ps.data.repository;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import androidx.media3.container.NalUnitUtil;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import dagger.hilt.android.qualifiers.ApplicationContext;
import defpackage.ae7;
import defpackage.aea;
import defpackage.bi8;
import defpackage.bz4;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e05;
import defpackage.e6a;
import defpackage.fa1;
import defpackage.i49;
import defpackage.ie7;
import defpackage.ig6;
import defpackage.iw7;
import defpackage.k63;
import defpackage.ke7;
import defpackage.kp6;
import defpackage.l38;
import defpackage.n25;
import defpackage.n41;
import defpackage.o29;
import defpackage.pq6;
import defpackage.qf8;
import defpackage.rf8;
import defpackage.ri8;
import defpackage.s38;
import defpackage.si8;
import defpackage.ta7;
import defpackage.u79;
import defpackage.uz1;
import defpackage.vx8;
import defpackage.we7;
import defpackage.wi8;
import defpackage.wy4;
import defpackage.x15;
import defpackage.xd7;
import defpackage.y41;
import defpackage.yj7;
import defpackage.yy4;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Singleton;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.ContinuationImpl;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.reflect.KTypeProjection;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u0000>\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0007\b\u0007\u0018\u0000 \u001f2\u00020\u0001:\u0002\u001f B\u001b\b\u0007\u0012\b\b\u0001\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004¢\u0006\u0004\b\u0006\u0010\u0007J\u000f\u0010\t\u001a\u00020\bH\u0002¢\u0006\u0004\b\t\u0010\nJ\u000f\u0010\u000b\u001a\u00020\bH\u0002¢\u0006\u0004\b\u000b\u0010\nJ\r\u0010\f\u001a\u00020\b¢\u0006\u0004\b\f\u0010\nJ\u0010\u0010\r\u001a\u00020\bH\u0086@¢\u0006\u0004\b\r\u0010\u000eJ\u0010\u0010\u0010\u001a\u00020\u000fH\u0086@¢\u0006\u0004\b\u0010\u0010\u000eR\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0003\u0010\u0011R\u0014\u0010\u0005\u001a\u00020\u00048\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0005\u0010\u0012R\u001c\u0010\u0015\u001a\n \u0014*\u0004\u0018\u00010\u00130\u00138\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0015\u0010\u0016R\u001a\u0010\u0018\u001a\b\u0012\u0004\u0012\u00020\b0\u00178\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0018\u0010\u0019R\u001d\u0010\u001b\u001a\b\u0012\u0004\u0012\u00020\b0\u001a8\u0006¢\u0006\f\n\u0004\b\u001b\u0010\u001c\u001a\u0004\b\u001d\u0010\u001e¨\u0006!"}, d2 = {"Lcom/strmr/ps/data/repository/AppConfigRepository;", "", "Landroid/content/Context;", "context", "Lxd7;", "postgrest", "<init>", "(Landroid/content/Context;Lxd7;)V", "", "getCachedProRequired", "()Z", "isCacheStale", "isProRequired", "fetchProRequired", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "Le6a;", "refreshIfStale", "Landroid/content/Context;", "Lxd7;", "Landroid/content/SharedPreferences;", "kotlin.jvm.PlatformType", "prefs", "Landroid/content/SharedPreferences;", "Lig6;", "_proRequired", "Lig6;", "Lo29;", "proRequired", "Lo29;", "getProRequired", "()Lo29;", "Companion", "AppConfigRow", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class AppConfigRepository {
    private static final long CACHE_TTL_MS = 3600000;

    @kp6
    private static final String KEY_PRO_REQUIRED = "pro_required";

    @kp6
    private static final String PREFS_NAME = "app_config_prefs";

    @kp6
    private static final String PREF_LAST_FETCH = "last_fetch_time";

    @kp6
    private static final String PREF_PRO_REQUIRED = "pro_required";

    @kp6
    private static final String TABLE_APP_CONFIG = "app_config";

    @kp6
    private static final String TAG = "AppConfigRepository";

    @kp6
    private final ig6<Boolean> _proRequired;

    @kp6
    private final Context context;

    @kp6
    private final xd7 postgrest;
    private final SharedPreferences prefs;

    @kp6
    private final o29<Boolean> proRequired;

    @si8
    @Metadata(d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u000e\n\u0002\u0010\u000b\n\u0002\b\f\b\u0083\b\u0018\u0000 ,2\u00020\u0001:\u0002-,B#\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004\u0012\n\b\u0002\u0010\u0006\u001a\u0004\u0018\u00010\u0002¢\u0006\u0004\b\u0007\u0010\bB9\b\u0010\u0012\u0006\u0010\n\u001a\u00020\t\u0012\b\u0010\u0003\u001a\u0004\u0018\u00010\u0002\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0004\u0012\b\u0010\u0006\u001a\u0004\u0018\u00010\u0002\u0012\b\u0010\f\u001a\u0004\u0018\u00010\u000b¢\u0006\u0004\b\u0007\u0010\rJ'\u0010\u0016\u001a\u00020\u00132\u0006\u0010\u000e\u001a\u00020\u00002\u0006\u0010\u0010\u001a\u00020\u000f2\u0006\u0010\u0012\u001a\u00020\u0011H\u0001¢\u0006\u0004\b\u0014\u0010\u0015J\u0010\u0010\u0017\u001a\u00020\u0002HÆ\u0003¢\u0006\u0004\b\u0017\u0010\u0018J\u0010\u0010\u0019\u001a\u00020\u0004HÆ\u0003¢\u0006\u0004\b\u0019\u0010\u001aJ\u0012\u0010\u001b\u001a\u0004\u0018\u00010\u0002HÆ\u0003¢\u0006\u0004\b\u001b\u0010\u0018J0\u0010\u001c\u001a\u00020\u00002\b\b\u0002\u0010\u0003\u001a\u00020\u00022\b\b\u0002\u0010\u0005\u001a\u00020\u00042\n\b\u0002\u0010\u0006\u001a\u0004\u0018\u00010\u0002HÆ\u0001¢\u0006\u0004\b\u001c\u0010\u001dJ\u0010\u0010\u001e\u001a\u00020\u0002HÖ\u0001¢\u0006\u0004\b\u001e\u0010\u0018J\u0010\u0010\u001f\u001a\u00020\tHÖ\u0001¢\u0006\u0004\b\u001f\u0010 J\u001a\u0010#\u001a\u00020\"2\b\u0010!\u001a\u0004\u0018\u00010\u0001HÖ\u0003¢\u0006\u0004\b#\u0010$R\u0017\u0010\u0003\u001a\u00020\u00028\u0006¢\u0006\f\n\u0004\b\u0003\u0010%\u001a\u0004\b&\u0010\u0018R\u0017\u0010\u0005\u001a\u00020\u00048\u0006¢\u0006\f\n\u0004\b\u0005\u0010'\u001a\u0004\b(\u0010\u001aR\"\u0010\u0006\u001a\u0004\u0018\u00010\u00028\u0006X\u0087\u0004¢\u0006\u0012\n\u0004\b\u0006\u0010%\u0012\u0004\b*\u0010+\u001a\u0004\b)\u0010\u0018¨\u0006."}, d2 = {"Lcom/strmr/ps/data/repository/AppConfigRepository$AppConfigRow;", "", "", "key", "Lwy4;", AppMeasurementSdk.ConditionalUserProperty.VALUE, "updatedAt", "<init>", "(Ljava/lang/String;Lwy4;Ljava/lang/String;)V", "", "seen0", "Lwi8;", "serializationConstructorMarker", "(ILjava/lang/String;Lwy4;Ljava/lang/String;Lwi8;)V", "self", "Lfa1;", "output", "Lbi8;", "serialDesc", "Le6a;", "write$Self$app_sideloadRelease", "(Lcom/strmr/ps/data/repository/AppConfigRepository$AppConfigRow;Lfa1;Lbi8;)V", "write$Self", "component1", "()Ljava/lang/String;", "component2", "()Lwy4;", "component3", "copy", "(Ljava/lang/String;Lwy4;Ljava/lang/String;)Lcom/strmr/ps/data/repository/AppConfigRepository$AppConfigRow;", "toString", "hashCode", "()I", "other", "", "equals", "(Ljava/lang/Object;)Z", "Ljava/lang/String;", "getKey", "Lwy4;", "getValue", "getUpdatedAt", "getUpdatedAt$annotations", "()V", "Companion", "$serializer", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final /* data */ class AppConfigRow {

        /* JADX INFO: renamed from: Companion, reason: from kotlin metadata */
        @kp6
        public static final Companion INSTANCE = new Companion(null);

        @kp6
        private final String key;

        @pq6
        private final String updatedAt;

        @kp6
        private final wy4 value;

        @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\u0002\u0010\u0003J\u0013\u0010\u0006\u001a\b\u0012\u0004\u0012\u00020\u00050\u0004¢\u0006\u0004\b\u0006\u0010\u0007¨\u0006\b"}, d2 = {"Lcom/strmr/ps/data/repository/AppConfigRepository$AppConfigRow$Companion;", "", "<init>", "()V", "Ln25;", "Lcom/strmr/ps/data/repository/AppConfigRepository$AppConfigRow;", "serializer", "()Ln25;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
        public static final class Companion {
            private Companion() {
            }

            @kp6
            public final n25<AppConfigRow> serializer() {
                return AppConfigRepository$AppConfigRow$$serializer.INSTANCE;
            }

            public /* synthetic */ Companion(uz1 uz1Var) {
                this();
            }
        }

        public /* synthetic */ AppConfigRow(int i, String str, wy4 wy4Var, String str2, wi8 wi8Var) {
            if (3 != (i & 3)) {
                ta7.a(i, 3, AppConfigRepository$AppConfigRow$$serializer.INSTANCE.getDescriptor());
                throw null;
            }
            this.key = str;
            this.value = wy4Var;
            if ((i & 4) == 0) {
                this.updatedAt = null;
            } else {
                this.updatedAt = str2;
            }
        }

        public static /* synthetic */ AppConfigRow copy$default(AppConfigRow appConfigRow, String str, wy4 wy4Var, String str2, int i, Object obj) {
            if ((i & 1) != 0) {
                str = appConfigRow.key;
            }
            if ((i & 2) != 0) {
                wy4Var = appConfigRow.value;
            }
            if ((i & 4) != 0) {
                str2 = appConfigRow.updatedAt;
            }
            return appConfigRow.copy(str, wy4Var, str2);
        }

        @ri8
        public static /* synthetic */ void getUpdatedAt$annotations() {
        }

        @x15
        public static final /* synthetic */ void write$Self$app_sideloadRelease(AppConfigRow self, fa1 output, bi8 serialDesc) {
            output.n(serialDesc, 0, self.key);
            output.q(serialDesc, 1, bz4.a, self.value);
            if (!output.e(serialDesc, 2) && self.updatedAt == null) {
                return;
            }
            output.ae(serialDesc, 2, u79.a, self.updatedAt);
        }

        @kp6
        /* JADX INFO: renamed from: component1, reason: from getter */
        public final String getKey() {
            return this.key;
        }

        @kp6
        /* JADX INFO: renamed from: component2, reason: from getter */
        public final wy4 getValue() {
            return this.value;
        }

        @pq6
        /* JADX INFO: renamed from: component3, reason: from getter */
        public final String getUpdatedAt() {
            return this.updatedAt;
        }

        @kp6
        public final AppConfigRow copy(@kp6 String key, @kp6 wy4 value, @pq6 String updatedAt) {
            cr4.g(key, "key");
            cr4.g(value, AppMeasurementSdk.ConditionalUserProperty.VALUE);
            return new AppConfigRow(key, value, updatedAt);
        }

        public boolean equals(@pq6 Object other) {
            if (this == other) {
                return true;
            }
            if (!(other instanceof AppConfigRow)) {
                return false;
            }
            AppConfigRow appConfigRow = (AppConfigRow) other;
            return cr4.b(this.key, appConfigRow.key) && cr4.b(this.value, appConfigRow.value) && cr4.b(this.updatedAt, appConfigRow.updatedAt);
        }

        @kp6
        public final String getKey() {
            return this.key;
        }

        @pq6
        public final String getUpdatedAt() {
            return this.updatedAt;
        }

        @kp6
        public final wy4 getValue() {
            return this.value;
        }

        public int hashCode() {
            int iHashCode = (this.value.hashCode() + (this.key.hashCode() * 31)) * 31;
            String str = this.updatedAt;
            return iHashCode + (str == null ? 0 : str.hashCode());
        }

        @kp6
        public String toString() {
            String str = this.key;
            wy4 wy4Var = this.value;
            String str2 = this.updatedAt;
            StringBuilder sb = new StringBuilder("AppConfigRow(key=");
            sb.append(str);
            sb.append(", value=");
            sb.append(wy4Var);
            sb.append(", updatedAt=");
            return n41.s(sb, str2, ")");
        }

        public AppConfigRow(@kp6 String str, @kp6 wy4 wy4Var, @pq6 String str2) {
            cr4.g(str, "key");
            cr4.g(wy4Var, AppMeasurementSdk.ConditionalUserProperty.VALUE);
            this.key = str;
            this.value = wy4Var;
            this.updatedAt = str2;
        }

        public /* synthetic */ AppConfigRow(String str, wy4 wy4Var, String str2, int i, uz1 uz1Var) {
            this(str, wy4Var, (i & 4) != 0 ? null : str2);
        }
    }

    /* JADX INFO: renamed from: com.strmr.ps.data.repository.AppConfigRepository$fetchProRequired$1, reason: invalid class name */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @DebugMetadata(c = "com.strmr.ps.data.repository.AppConfigRepository", f = "AppConfigRepository.kt", i = {0}, l = {153}, m = "fetchProRequired", n = {"this"}, s = {"L$0"})
    public static final class AnonymousClass1 extends ContinuationImpl {
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public AnonymousClass1(Continuation<? super AnonymousClass1> continuation) {
            super(continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        @pq6
        public final Object invokeSuspend(@kp6 Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return AppConfigRepository.this.fetchProRequired(this);
        }
    }

    @Inject
    public AppConfigRepository(@ApplicationContext @kp6 Context context, @kp6 xd7 xd7Var) {
        cr4.g(context, "context");
        cr4.g(xd7Var, "postgrest");
        this.context = context;
        this.postgrest = xd7Var;
        this.prefs = context.getSharedPreferences(PREFS_NAME, 0);
        ig6<Boolean> ig6VarA = i49.a(Boolean.valueOf(getCachedProRequired()));
        this._proRequired = ig6VarA;
        this.proRequired = k63.b(ig6VarA);
    }

    private final boolean getCachedProRequired() {
        return this.prefs.getBoolean("pro_required", false);
    }

    private final boolean isCacheStale() {
        return System.currentTimeMillis() - this.prefs.getLong(PREF_LAST_FETCH, 0L) > CACHE_TTL_MS;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object fetchProRequired(@kp6 Continuation<? super Boolean> continuation) {
        AnonymousClass1 anonymousClass1;
        AppConfigRepository appConfigRepository;
        boolean cachedProRequired;
        wy4 value;
        Boolean boolD;
        if (continuation instanceof AnonymousClass1) {
            anonymousClass1 = (AnonymousClass1) continuation;
            int i = anonymousClass1.label;
            if ((i & Integer.MIN_VALUE) != 0) {
                anonymousClass1.label = i - Integer.MIN_VALUE;
            } else {
                anonymousClass1 = new AnonymousClass1(continuation);
            }
        }
        Object objA = anonymousClass1.result;
        ck1 ck1Var = ck1.a;
        int i2 = anonymousClass1.label;
        if (i2 == 0) {
            s38.b(objA);
            try {
                ke7 ke7VarL = this.postgrest.l(TABLE_APP_CONFIG);
                ie7 ie7Var = ke7VarL.a;
                yj7 yj7Var = ie7Var.d.b;
                rf8 rf8Var = new rf8(yj7Var);
                LinkedHashMap linkedHashMap = rf8Var.b;
                new ae7(yj7Var, linkedHashMap).b("key", "pro_required");
                linkedHashMap.put("select", y41.am("*"));
                qf8 qf8Var = new qf8(aea.a(linkedHashMap), ke7VarL.c, rf8Var.c.m());
                l38 l38Var = l38.a;
                String str = ke7VarL.b;
                anonymousClass1.L$0 = this;
                anonymousClass1.label = 1;
                objA = l38Var.a(ie7Var, str, qf8Var, anonymousClass1);
                if (objA == ck1Var) {
                    return ck1Var;
                }
                appConfigRepository = this;
            } catch (Exception e) {
                e = e;
                appConfigRepository = this;
                Log.e(TAG, "Failed to fetch pro_required, using cached value", e);
                cachedProRequired = appConfigRepository.getCachedProRequired();
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            appConfigRepository = (AppConfigRepository) anonymousClass1.L$0;
            try {
                s38.b(objA);
            } catch (Exception e2) {
                e = e2;
                Log.e(TAG, "Failed to fetch pro_required, using cached value", e);
                cachedProRequired = appConfigRepository.getCachedProRequired();
            }
        }
        we7 we7Var = (we7) objA;
        AppConfigRow appConfigRow = (AppConfigRow) y41.ab((List) we7Var.c.getE().b(iw7.b(List.class, KTypeProjection.INSTANCE.invariant(iw7.a(AppConfigRow.class))), we7Var.a));
        cachedProRequired = false;
        if (appConfigRow != null && (value = appConfigRow.getValue()) != null && (value instanceof e05) && (boolD = yy4.d((e05) value)) != null) {
            cachedProRequired = boolD.booleanValue();
        }
        appConfigRepository.prefs.edit().putBoolean("pro_required", cachedProRequired).putLong(PREF_LAST_FETCH, System.currentTimeMillis()).apply();
        appConfigRepository._proRequired.setValue(Boxing.boxBoolean(cachedProRequired));
        return Boxing.boxBoolean(cachedProRequired);
    }

    @kp6
    public final o29<Boolean> getProRequired() {
        return this.proRequired;
    }

    public final boolean isProRequired() {
        return ((Boolean) this._proRequired.getValue()).booleanValue();
    }

    @pq6
    public final Object refreshIfStale(@kp6 Continuation<? super e6a> continuation) {
        boolean zIsCacheStale = isCacheStale();
        e6a e6aVar = e6a.a;
        if (zIsCacheStale) {
            Object objFetchProRequired = fetchProRequired(continuation);
            return objFetchProRequired == ck1.a ? objFetchProRequired : e6aVar;
        }
        Objects.toString(this._proRequired.getValue());
        return e6aVar;
    }
}
