package defpackage;

import com.strmr.ps.data.model.trakt.TraktTokenResponse;
import com.strmr.ps.data.remote.api.TraktApiService;
import defpackage.q38;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import retrofit2.HttpException;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.ui.settings.fragments.AccountsFragment$pollForDeviceToken$1", f = "AccountsFragment.kt", i = {0, 0, 0, 0, 3, 3, 3, 3}, l = {792, 801, 810, 819, 823}, m = "invokeSuspend", n = {"$this$launch", "expiresAt", "pollDelay", "consecutiveServerErrors", "$this$launch", "expiresAt", "pollDelay", "consecutiveServerErrors"}, s = {"L$0", "J$0", "J$1", "I$0", "L$0", "J$0", "J$1", "I$0"})
final class h5 extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public long a;
    public long b;
    public int c;
    public int d;
    public /* synthetic */ Object e;
    public final /* synthetic */ int f;
    public final /* synthetic */ int i;
    public final /* synthetic */ a4 j;
    public final /* synthetic */ String k;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public h5(int i, int i2, a4 a4Var, String str, Continuation continuation) {
        super(2, continuation);
        this.f = i;
        this.i = i2;
        this.j = a4Var;
        this.k = str;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        h5 h5Var = new h5(this.f, this.i, this.j, this.k, continuation);
        h5Var.e = obj;
        return h5Var;
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((h5) create((ak1) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Can't wrap try/catch for region: R(10:33|34|78|35|(1:37)|38|46|(1:48)(1:49)|50|(2:52|(0)(1:75))(3:55|(1:65)(2:59|(2:61|(0)(0))(1:64))|66)) */
    /* JADX WARN: Code restructure failed: missing block: B:67:0x0116, code lost:
    
        if (defpackage.h32.a(r12, r19) == r2) goto L74;
     */
    /* JADX WARN: Removed duplicated region for block: B:48:0x00c2  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x00c4  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x00c9  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00d6  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x012a  */
    /* JADX WARN: Removed duplicated region for block: B:75:0x013f A[RETURN] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:67:0x0116 -> B:69:0x0119). Please report as a decompilation issue!!! */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        long jCurrentTimeMillis;
        long j;
        ak1 ak1Var;
        int i;
        ak1 ak1Var2;
        Throwable th;
        Object objA;
        TraktTokenResponse traktTokenResponse;
        Object objPollDeviceToken;
        ck1 ck1Var = ck1.a;
        int i2 = this.d;
        e6a e6aVar = e6a.a;
        a4 a4Var = this.j;
        if (i2 == 0) {
            s38.b(obj);
            ak1 ak1Var3 = (ak1) this.e;
            jCurrentTimeMillis = (((long) this.f) * 1000) + System.currentTimeMillis();
            int i3 = this.i;
            if (i3 < 1) {
                i3 = 1;
            }
            j = ((long) i3) * 1000;
            ak1Var = ak1Var3;
            i = 0;
            if (bk1.d(ak1Var)) {
            }
            if (bk1.d(ak1Var)) {
            }
            return e6aVar;
        }
        if (i2 != 1) {
            if (i2 == 2) {
                s38.b(obj);
                return e6aVar;
            }
            if (i2 == 3) {
                s38.b(obj);
                return e6aVar;
            }
            if (i2 != 4) {
                if (i2 != 5) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
                return e6aVar;
            }
            int i4 = this.c;
            j = this.b;
            jCurrentTimeMillis = this.a;
            ak1 ak1Var4 = (ak1) this.e;
            s38.b(obj);
            ak1Var2 = ak1Var4;
            char c = 4;
            char c2 = 3;
            char c3 = 2;
            ak1Var = ak1Var2;
            i = i4;
            if (bk1.d(ak1Var) || System.currentTimeMillis() >= jCurrentTimeMillis) {
                if (bk1.d(ak1Var)) {
                    m12 m12Var = sc2.a;
                    qm5 qm5Var = sm5.a;
                    g5 g5Var = new g5(a4Var, null);
                    this.e = null;
                    this.d = 5;
                    if (wj0.f(qm5Var, g5Var, this) == ck1Var) {
                    }
                }
                return e6aVar;
            }
            String str = this.k;
            try {
            } catch (Throwable th2) {
                th = th2;
                ak1Var2 = ak1Var;
            }
            TraktApiService traktApiService = a4Var.m;
            if (traktApiService == null) {
                ak1Var2 = ak1Var;
                cr4.n("traktApiService");
                throw null;
            }
            ak1Var2 = ak1Var;
            this.e = ak1Var2;
            this.a = jCurrentTimeMillis;
            this.b = j;
            this.c = i;
            this.d = 1;
            objPollDeviceToken = traktApiService.pollDeviceToken("a380a31ce8c76681c825decf7c03e5ef1e6cce3e2657fc9289e0c3594b1a555b", "d1096df8b09eca9acb9c6bda2593833743b8106ce437b4ae6498a7d0036300ce", str, this);
            if (objPollDeviceToken == ck1Var) {
            }
            objA = (TraktTokenResponse) objPollDeviceToken;
            traktTokenResponse = (TraktTokenResponse) (!(objA instanceof q38.b) ? null : objA);
            if (traktTokenResponse == null) {
                this.e = null;
                this.d = 2;
                if (a4.l(a4Var, traktTokenResponse, this) != ck1Var) {
                    return e6aVar;
                }
            } else {
                c3 = 2;
                Throwable thA = q38.a(objA);
                if (!(thA instanceof HttpException) || ((HttpException) thA).code() < 500) {
                    c2 = 3;
                    i4 = 0;
                } else {
                    int i5 = i + 1;
                    if (i5 >= 5) {
                        m12 m12Var2 = sc2.a;
                        qm5 qm5Var2 = sm5.a;
                        f5 f5Var = new f5(a4Var, null);
                        this.e = null;
                        this.d = 3;
                        if (wj0.f(qm5Var2, f5Var, this) == ck1Var) {
                        }
                    } else {
                        c2 = 3;
                        i4 = i5;
                    }
                }
                this.e = ak1Var2;
                this.a = jCurrentTimeMillis;
                this.b = j;
                this.c = i4;
                c = 4;
                this.d = 4;
            }
            th = th;
            objA = s38.a(th);
            traktTokenResponse = (TraktTokenResponse) (!(objA instanceof q38.b) ? null : objA);
            if (traktTokenResponse == null) {
            }
            return ck1Var;
        }
        i = this.c;
        j = this.b;
        jCurrentTimeMillis = this.a;
        ak1 ak1Var5 = (ak1) this.e;
        try {
            s38.b(obj);
            objPollDeviceToken = obj;
            ak1Var2 = ak1Var5;
        } catch (Throwable th3) {
            th = th3;
            ak1Var2 = ak1Var5;
            objA = s38.a(th);
            traktTokenResponse = (TraktTokenResponse) (!(objA instanceof q38.b) ? null : objA);
            if (traktTokenResponse == null) {
            }
        }
        objA = (TraktTokenResponse) objPollDeviceToken;
        traktTokenResponse = (TraktTokenResponse) (!(objA instanceof q38.b) ? null : objA);
        if (traktTokenResponse == null) {
        }
    }
}
