package com.google.firebase.sessions.settings;

import A4.d;
import B4.a;
import C4.e;
import C4.j;
import android.util.Log;
import androidx.compose.runtime.ComposerImplKt;
import androidx.media3.extractor.ts.TsExtractor;
import kotlin.jvm.internal.C;
import kotlin.jvm.internal.o;
import m3.AbstractC2467b;
import org.json.JSONException;
import org.json.JSONObject;
import w4.C3137A;

/* JADX INFO: loaded from: classes3.dex */
@e(c = "com.google.firebase.sessions.settings.RemoteSettings$updateSettings$2$1", f = "RemoteSettings.kt", l = {ComposerImplKt.nodeKey, 128, 131, 133, TsExtractor.TS_STREAM_TYPE_SPLICE_INFO, TsExtractor.TS_STREAM_TYPE_DTS_HD}, m = "invokeSuspend")
public final class RemoteSettings$updateSettings$2$1 extends j implements J4.e {
    /* synthetic */ Object L$0;
    Object L$1;
    Object L$2;
    int label;
    final /* synthetic */ RemoteSettings this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public RemoteSettings$updateSettings$2$1(RemoteSettings remoteSettings, d dVar) {
        super(2, dVar);
        this.this$0 = remoteSettings;
    }

    @Override // C4.a
    public final d create(Object obj, d dVar) {
        RemoteSettings$updateSettings$2$1 remoteSettings$updateSettings$2$1 = new RemoteSettings$updateSettings$2$1(this.this$0, dVar);
        remoteSettings$updateSettings$2$1.L$0 = obj;
        return remoteSettings$updateSettings$2$1;
    }

    /* JADX WARN: Code restructure failed: missing block: B:56:0x0151, code lost:
    
        if (r14.updateSessionCacheDuration(r0, r13) == r4) goto L66;
     */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00f9  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x011a  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x013a  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x0156  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0159  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x0195 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:67:0x0196 A[RETURN] */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws JSONException {
        C c6;
        Boolean bool;
        C c7;
        C c8;
        C c9;
        C c10;
        C3137A c3137a;
        SettingsCache settingsCache;
        Long l;
        a aVar = a.f492a;
        int i6 = this.label;
        C3137A c3137a2 = C3137A.f25453a;
        switch (i6) {
            case 0:
                AbstractC2467b.l(obj);
                JSONObject jSONObject = (JSONObject) this.L$0;
                Log.d(RemoteSettings.TAG, "Fetched settings: " + jSONObject);
                C c11 = new C();
                c6 = new C();
                C c12 = new C();
                if (jSONObject.has("app_quality")) {
                    Object obj2 = jSONObject.get("app_quality");
                    o.f(obj2, "null cannot be cast to non-null type org.json.JSONObject");
                    JSONObject jSONObject2 = (JSONObject) obj2;
                    try {
                        bool = jSONObject2.has("sessions_enabled") ? (Boolean) jSONObject2.get("sessions_enabled") : null;
                    } catch (JSONException e6) {
                        e = e6;
                        bool = null;
                    }
                    try {
                        if (jSONObject2.has("sampling_rate")) {
                            c11.f20115a = (Double) jSONObject2.get("sampling_rate");
                        }
                        if (jSONObject2.has("session_timeout_seconds")) {
                            c6.f20115a = (Integer) jSONObject2.get("session_timeout_seconds");
                        }
                        if (jSONObject2.has("cache_duration")) {
                            c12.f20115a = (Integer) jSONObject2.get("cache_duration");
                        }
                    } catch (JSONException e7) {
                        e = e7;
                        Log.e(RemoteSettings.TAG, "Error parsing the configs remotely fetched: ", e);
                    }
                } else {
                    bool = null;
                }
                if (bool != null) {
                    SettingsCache settingsCache2 = this.this$0.getSettingsCache();
                    this.L$0 = c11;
                    this.L$1 = c6;
                    this.L$2 = c12;
                    this.label = 1;
                    if (settingsCache2.updateSettingsEnabled(bool, this) != aVar) {
                        c9 = c11;
                        c10 = c6;
                        c8 = c12;
                        c6 = c10;
                        c7 = c9;
                        if (((Integer) c6.f20115a) != null) {
                            SettingsCache settingsCache3 = this.this$0.getSettingsCache();
                            Integer num = (Integer) c6.f20115a;
                            this.L$0 = c7;
                            this.L$1 = c8;
                            this.L$2 = null;
                            this.label = 2;
                            if (settingsCache3.updateSessionRestartTimeout(num, this) != aVar) {
                            }
                        }
                        if (((Double) c7.f20115a) != null) {
                            SettingsCache settingsCache4 = this.this$0.getSettingsCache();
                            Double d6 = (Double) c7.f20115a;
                            this.L$0 = c8;
                            this.L$1 = null;
                            this.L$2 = null;
                            this.label = 3;
                            if (settingsCache4.updateSamplingRate(d6, this) != aVar) {
                            }
                        }
                        if (((Integer) c8.f20115a) != null) {
                            SettingsCache settingsCache5 = this.this$0.getSettingsCache();
                            Integer num2 = (Integer) c8.f20115a;
                            this.L$0 = null;
                            this.L$1 = null;
                            this.L$2 = null;
                            this.label = 4;
                        } else {
                            c3137a = null;
                            if (c3137a == null) {
                                SettingsCache settingsCache6 = this.this$0.getSettingsCache();
                                Integer num3 = new Integer(86400);
                                this.L$0 = null;
                                this.L$1 = null;
                                this.L$2 = null;
                                this.label = 5;
                                if (settingsCache6.updateSessionCacheDuration(num3, this) != aVar) {
                                }
                            }
                            settingsCache = this.this$0.getSettingsCache();
                            l = new Long(System.currentTimeMillis());
                            this.L$0 = null;
                            this.L$1 = null;
                            this.L$2 = null;
                            this.label = 6;
                            if (settingsCache.updateSessionCacheUpdatedTime(l, this) == aVar) {
                                return c3137a2;
                            }
                        }
                        break;
                    }
                    return aVar;
                }
                c7 = c11;
                c8 = c12;
                if (((Integer) c6.f20115a) != null) {
                }
                if (((Double) c7.f20115a) != null) {
                }
                if (((Integer) c8.f20115a) != null) {
                }
                break;
            case 1:
                c8 = (C) this.L$2;
                c10 = (C) this.L$1;
                c9 = (C) this.L$0;
                AbstractC2467b.l(obj);
                c6 = c10;
                c7 = c9;
                if (((Integer) c6.f20115a) != null) {
                }
                if (((Double) c7.f20115a) != null) {
                }
                if (((Integer) c8.f20115a) != null) {
                }
                break;
            case 2:
                c8 = (C) this.L$1;
                c7 = (C) this.L$0;
                AbstractC2467b.l(obj);
                if (((Double) c7.f20115a) != null) {
                }
                if (((Integer) c8.f20115a) != null) {
                }
                break;
            case 3:
                c8 = (C) this.L$0;
                AbstractC2467b.l(obj);
                if (((Integer) c8.f20115a) != null) {
                }
                break;
            case 4:
                AbstractC2467b.l(obj);
                c3137a = c3137a2;
                if (c3137a == null) {
                }
                settingsCache = this.this$0.getSettingsCache();
                l = new Long(System.currentTimeMillis());
                this.L$0 = null;
                this.L$1 = null;
                this.L$2 = null;
                this.label = 6;
                if (settingsCache.updateSessionCacheUpdatedTime(l, this) == aVar) {
                    return aVar;
                }
                break;
            case 5:
                AbstractC2467b.l(obj);
                settingsCache = this.this$0.getSettingsCache();
                l = new Long(System.currentTimeMillis());
                this.L$0 = null;
                this.L$1 = null;
                this.L$2 = null;
                this.label = 6;
                if (settingsCache.updateSessionCacheUpdatedTime(l, this) == aVar) {
                }
                break;
            case 6:
                AbstractC2467b.l(obj);
                return c3137a2;
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }

    @Override // J4.e
    public final Object invoke(JSONObject jSONObject, d dVar) {
        return ((RemoteSettings$updateSettings$2$1) create(jSONObject, dVar)).invokeSuspend(C3137A.f25453a);
    }
}
