package f;

import c.e;
import java.lang.reflect.Method;
import kotlinx.coroutines.CancellableContinuation;
import kotlinx.coroutines.CancellableContinuationImpl;

/* JADX INFO: compiled from: KotlinExtensions.kt */
/* JADX INFO: loaded from: classes.dex */
public final class m {

    /* JADX INFO: compiled from: KotlinExtensions.kt */
    static final class a extends c.q.d.k implements c.q.c.b<Throwable, c.j> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ f.d f1659b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(f.d dVar) {
            super(1);
            this.f1659b = dVar;
        }

        public final void b(Throwable th) {
            this.f1659b.cancel();
        }

        @Override // c.q.c.b
        public /* bridge */ /* synthetic */ c.j invoke(Throwable th) {
            b(th);
            return c.j.f1417a;
        }
    }

    /* JADX INFO: compiled from: KotlinExtensions.kt */
    static final class b extends c.q.d.k implements c.q.c.b<Throwable, c.j> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ f.d f1660b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(f.d dVar) {
            super(1);
            this.f1660b = dVar;
        }

        public final void b(Throwable th) {
            this.f1660b.cancel();
        }

        @Override // c.q.c.b
        public /* bridge */ /* synthetic */ c.j invoke(Throwable th) {
            b(th);
            return c.j.f1417a;
        }
    }

    /* JADX INFO: Add missing generic type declarations: [T] */
    /* JADX INFO: compiled from: KotlinExtensions.kt */
    public static final class c<T> implements f.f<T> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ CancellableContinuation f1661b;

        c(CancellableContinuation cancellableContinuation) {
            this.f1661b = cancellableContinuation;
        }

        @Override // f.f
        public void a(f.d<T> dVar, Throwable th) {
            c.q.d.j.c(dVar, "call");
            c.q.d.j.c(th, "t");
            c.n.a aVar = this.f1661b;
            e.a aVar2 = c.e.f1415b;
            Object objA = c.f.a(th);
            c.e.a(objA);
            aVar.a(objA);
        }

        @Override // f.f
        public void b(f.d<T> dVar, t<T> tVar) {
            c.q.d.j.c(dVar, "call");
            c.q.d.j.c(tVar, "response");
            if (!tVar.d()) {
                c.n.a aVar = this.f1661b;
                j jVar = new j(tVar);
                e.a aVar2 = c.e.f1415b;
                Object objA = c.f.a(jVar);
                c.e.a(objA);
                aVar.a(objA);
                return;
            }
            T tA = tVar.a();
            if (tA != null) {
                c.n.a aVar3 = this.f1661b;
                e.a aVar4 = c.e.f1415b;
                c.e.a(tA);
                aVar3.a(tA);
                return;
            }
            Object objTag = dVar.request().tag(l.class);
            if (objTag == null) {
                c.q.d.j.g();
                throw null;
            }
            c.q.d.j.b(objTag, "call.request().tag(Invocation::class.java)!!");
            Method methodA = ((l) objTag).a();
            StringBuilder sb = new StringBuilder();
            sb.append("Response from ");
            c.q.d.j.b(methodA, "method");
            Class<?> declaringClass = methodA.getDeclaringClass();
            c.q.d.j.b(declaringClass, "method.declaringClass");
            sb.append(declaringClass.getName());
            sb.append('.');
            sb.append(methodA.getName());
            sb.append(" was null but response body type was declared as non-null");
            c.c cVar = new c.c(sb.toString());
            c.n.a aVar5 = this.f1661b;
            e.a aVar6 = c.e.f1415b;
            Object objA2 = c.f.a(cVar);
            c.e.a(objA2);
            aVar5.a(objA2);
        }
    }

    /* JADX INFO: Add missing generic type declarations: [T] */
    /* JADX INFO: compiled from: KotlinExtensions.kt */
    public static final class d<T> implements f.f<T> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ CancellableContinuation f1662b;

        d(CancellableContinuation cancellableContinuation) {
            this.f1662b = cancellableContinuation;
        }

        @Override // f.f
        public void a(f.d<T> dVar, Throwable th) {
            c.q.d.j.c(dVar, "call");
            c.q.d.j.c(th, "t");
            c.n.a aVar = this.f1662b;
            e.a aVar2 = c.e.f1415b;
            Object objA = c.f.a(th);
            c.e.a(objA);
            aVar.a(objA);
        }

        @Override // f.f
        public void b(f.d<T> dVar, t<T> tVar) {
            c.q.d.j.c(dVar, "call");
            c.q.d.j.c(tVar, "response");
            if (tVar.d()) {
                c.n.a aVar = this.f1662b;
                T tA = tVar.a();
                e.a aVar2 = c.e.f1415b;
                c.e.a(tA);
                aVar.a(tA);
                return;
            }
            c.n.a aVar3 = this.f1662b;
            j jVar = new j(tVar);
            e.a aVar4 = c.e.f1415b;
            Object objA = c.f.a(jVar);
            c.e.a(objA);
            aVar3.a(objA);
        }
    }

    /* JADX INFO: compiled from: KotlinExtensions.kt */
    static final class e extends c.q.d.k implements c.q.c.b<Throwable, c.j> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ f.d f1663b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        e(f.d dVar) {
            super(1);
            this.f1663b = dVar;
        }

        public final void b(Throwable th) {
            this.f1663b.cancel();
        }

        @Override // c.q.c.b
        public /* bridge */ /* synthetic */ c.j invoke(Throwable th) {
            b(th);
            return c.j.f1417a;
        }
    }

    /* JADX INFO: Add missing generic type declarations: [T] */
    /* JADX INFO: compiled from: KotlinExtensions.kt */
    public static final class f<T> implements f.f<T> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ CancellableContinuation f1664b;

        f(CancellableContinuation cancellableContinuation) {
            this.f1664b = cancellableContinuation;
        }

        @Override // f.f
        public void a(f.d<T> dVar, Throwable th) {
            c.q.d.j.c(dVar, "call");
            c.q.d.j.c(th, "t");
            c.n.a aVar = this.f1664b;
            e.a aVar2 = c.e.f1415b;
            Object objA = c.f.a(th);
            c.e.a(objA);
            aVar.a(objA);
        }

        @Override // f.f
        public void b(f.d<T> dVar, t<T> tVar) {
            c.q.d.j.c(dVar, "call");
            c.q.d.j.c(tVar, "response");
            c.n.a aVar = this.f1664b;
            e.a aVar2 = c.e.f1415b;
            c.e.a(tVar);
            aVar.a(tVar);
        }
    }

    /* JADX INFO: compiled from: KotlinExtensions.kt */
    static final class g implements Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ c.n.a f1665b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ Exception f1666c;

        g(c.n.a aVar, Exception exc) {
            this.f1665b = aVar;
            this.f1666c = exc;
        }

        @Override // java.lang.Runnable
        public final void run() {
            c.n.a aVarA = c.n.d.c.a(this.f1665b);
            Exception exc = this.f1666c;
            e.a aVar = c.e.f1415b;
            Object objA = c.f.a(exc);
            c.e.a(objA);
            aVarA.a(objA);
        }
    }

    /* JADX INFO: compiled from: KotlinExtensions.kt */
    @c.n.e.a.d(c = "retrofit2.KotlinExtensions", f = "KotlinExtensions.kt", l = {113}, m = "suspendAndThrow")
    static final class h extends c.n.e.a.c {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        /* synthetic */ Object f1667e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        int f1668f;
        Object g;

        h(c.n.a aVar) {
            super(aVar);
        }

        @Override // c.n.e.a.a
        public final Object c(Object obj) {
            this.f1667e = obj;
            this.f1668f |= Integer.MIN_VALUE;
            return m.d(null, this);
        }
    }

    public static final <T> Object a(f.d<T> dVar, c.n.a<? super T> aVar) {
        CancellableContinuation cancellableContinuationImpl = new CancellableContinuationImpl(c.n.d.c.a(aVar), 1);
        CancellableContinuation cancellableContinuation = cancellableContinuationImpl;
        cancellableContinuation.invokeOnCancellation(new a(dVar));
        dVar.v(new c(cancellableContinuation));
        Object result = cancellableContinuationImpl.getResult();
        if (result == c.n.d.d.b()) {
            c.n.e.a.f.b(aVar);
        }
        return result;
    }

    public static final <T> Object b(f.d<T> dVar, c.n.a<? super T> aVar) {
        CancellableContinuation cancellableContinuationImpl = new CancellableContinuationImpl(c.n.d.c.a(aVar), 1);
        CancellableContinuation cancellableContinuation = cancellableContinuationImpl;
        cancellableContinuation.invokeOnCancellation(new b(dVar));
        dVar.v(new d(cancellableContinuation));
        Object result = cancellableContinuationImpl.getResult();
        if (result == c.n.d.d.b()) {
            c.n.e.a.f.b(aVar);
        }
        return result;
    }

    public static final <T> Object c(f.d<T> dVar, c.n.a<? super t<T>> aVar) {
        CancellableContinuation cancellableContinuationImpl = new CancellableContinuationImpl(c.n.d.c.a(aVar), 1);
        CancellableContinuation cancellableContinuation = cancellableContinuationImpl;
        cancellableContinuation.invokeOnCancellation(new e(dVar));
        dVar.v(new f(cancellableContinuation));
        Object result = cancellableContinuationImpl.getResult();
        if (result == c.n.d.d.b()) {
            c.n.e.a.f.b(aVar);
        }
        return result;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static final java.lang.Object d(java.lang.Exception r4, c.n.a<?> r5) throws java.lang.Throwable {
        /*
            boolean r0 = r5 instanceof f.m.h
            if (r0 == 0) goto L13
            r0 = r5
            f.m$h r0 = (f.m.h) r0
            int r1 = r0.f1668f
            r2 = -2147483648(0xffffffff80000000, float:-0.0)
            r3 = r1 & r2
            if (r3 == 0) goto L13
            int r1 = r1 - r2
            r0.f1668f = r1
            goto L18
        L13:
            f.m$h r0 = new f.m$h
            r0.<init>(r5)
        L18:
            java.lang.Object r5 = r0.f1667e
            java.lang.Object r1 = c.n.d.b.b()
            int r2 = r0.f1668f
            r3 = 1
            if (r2 == 0) goto L35
            if (r2 != r3) goto L2d
            java.lang.Object r4 = r0.g
            java.lang.Exception r4 = (java.lang.Exception) r4
            c.f.b(r5)
            goto L5c
        L2d:
            java.lang.IllegalStateException r4 = new java.lang.IllegalStateException
            java.lang.String r5 = "call to 'resume' before 'invoke' with coroutine"
            r4.<init>(r5)
            throw r4
        L35:
            c.f.b(r5)
            r0.g = r4
            r0.f1668f = r3
            kotlinx.coroutines.CoroutineDispatcher r5 = kotlinx.coroutines.Dispatchers.getDefault()
            c.n.c r2 = r0.d()
            f.m$g r3 = new f.m$g
            r3.<init>(r0, r4)
            r5.dispatch(r2, r3)
            java.lang.Object r4 = c.n.d.b.b()
            java.lang.Object r5 = c.n.d.b.b()
            if (r4 != r5) goto L59
            c.n.e.a.f.b(r0)
        L59:
            if (r4 != r1) goto L5c
            return r1
        L5c:
            c.j r4 = c.j.f1417a
            return r4
        */
        throw new UnsupportedOperationException("Method not decompiled: f.m.d(java.lang.Exception, c.n.a):java.lang.Object");
    }
}
