package retrofit2;

import defpackage.b45;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.dr4;
import defpackage.e6a;
import defpackage.kp6;
import defpackage.pq6;
import defpackage.r15;
import defpackage.s38;
import defpackage.sc2;
import defpackage.ts0;
import java.lang.reflect.Method;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.ContinuationImpl;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.DebugProbesKt;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000.\n\u0002\b\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u001a%\u0010\u0000\u001a\u0002H\u0001\"\b\b\u0000\u0010\u0001*\u00020\u0002*\b\u0012\u0004\u0012\u0002H\u00010\u0003H\u0086@ø\u0001\u0000¢\u0006\u0002\u0010\u0004\u001a+\u0010\u0000\u001a\u0004\u0018\u0001H\u0001\"\b\b\u0000\u0010\u0001*\u00020\u0002*\n\u0012\u0006\u0012\u0004\u0018\u0001H\u00010\u0003H\u0087@ø\u0001\u0000¢\u0006\u0004\b\u0005\u0010\u0004\u001a'\u0010\u0006\u001a\b\u0012\u0004\u0012\u0002H\u00010\u0007\"\u0004\b\u0000\u0010\u0001*\b\u0012\u0004\u0012\u0002H\u00010\u0003H\u0086@ø\u0001\u0000¢\u0006\u0002\u0010\u0004\u001a\u001a\u0010\b\u001a\u0002H\u0001\"\u0006\b\u0000\u0010\u0001\u0018\u0001*\u00020\tH\u0086\b¢\u0006\u0002\u0010\n\u001a\u0019\u0010\u000b\u001a\u00020\f*\u00060\rj\u0002`\u000eH\u0080@ø\u0001\u0000¢\u0006\u0002\u0010\u000f\u0082\u0002\u0004\n\u0002\b\u0019¨\u0006\u0010"}, d2 = {"await", "T", "", "Lretrofit2/Call;", "(Lretrofit2/Call;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "awaitNullable", "awaitResponse", "Lretrofit2/Response;", "create", "Lretrofit2/Retrofit;", "(Lretrofit2/Retrofit;)Ljava/lang/Object;", "suspendAndThrow", "", "Ljava/lang/Exception;", "Lkotlin/Exception;", "(Ljava/lang/Exception;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "retrofit"}, k = 2, mv = {1, 1, 15})
@r15
public final class KotlinExtensions {

    /* JADX INFO: renamed from: retrofit2.KotlinExtensions$suspendAndThrow$1, reason: invalid class name */
    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0018\n\u0000\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0001\u0010\u0000\u001a\u0004\u0018\u00010\u0001*\u00060\u0002j\u0002`\u00032\f\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005H\u0080@"}, d2 = {"suspendAndThrow", "", "Ljava/lang/Exception;", "Lkotlin/Exception;", "continuation", "Lkotlin/coroutines/Continuation;", ""}, k = 3, mv = {1, 1, 15})
    @DebugMetadata(c = "retrofit2.KotlinExtensions", f = "KotlinExtensions.kt", i = {0}, l = {113}, m = "suspendAndThrow", n = {"$this$suspendAndThrow"}, s = {"L$0"})
    public static final class AnonymousClass1 extends ContinuationImpl {
        Object L$0;
        int label;
        /* synthetic */ Object result;

        public AnonymousClass1(Continuation 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 KotlinExtensions.suspendAndThrow(null, this);
        }
    }

    @pq6
    public static final <T> Object await(@kp6 Call<T> call, @kp6 Continuation<? super T> continuation) {
        final ts0 ts0Var = new ts0(1, dr4.d(continuation));
        ts0Var.t(new KotlinExtensions$await$$inlined$suspendCancellableCoroutine$lambda$1(call));
        call.enqueue(new Callback<T>() { // from class: retrofit2.KotlinExtensions$await$2$2
            @Override // retrofit2.Callback
            public void onFailure(@kp6 Call<T> call2, @kp6 Throwable t) {
                cr4.h(call2, "call");
                cr4.h(t, "t");
                ts0Var.resumeWith(s38.a(t));
            }

            @Override // retrofit2.Callback
            public void onResponse(@kp6 Call<T> call2, @kp6 Response<T> response) {
                cr4.h(call2, "call");
                cr4.h(response, "response");
                if (!response.isSuccessful()) {
                    ts0Var.resumeWith(s38.a(new HttpException(response)));
                    return;
                }
                T tBody = response.body();
                if (tBody != null) {
                    ts0Var.resumeWith(tBody);
                    return;
                }
                Object objTag = call2.request().tag(Invocation.class);
                if (objTag == null) {
                    b45 b45Var = new b45();
                    cr4.k(b45Var, cr4.class.getName());
                    throw b45Var;
                }
                Method method = ((Invocation) objTag).method();
                StringBuilder sb = new StringBuilder("Response from ");
                cr4.c(method, "method");
                Class<?> declaringClass = method.getDeclaringClass();
                cr4.c(declaringClass, "method.declaringClass");
                sb.append(declaringClass.getName());
                sb.append('.');
                sb.append(method.getName());
                sb.append(" was null but response body type was declared as non-null");
                ts0Var.resumeWith(s38.a(new b45(sb.toString())));
            }
        });
        Object objQ = ts0Var.q();
        if (objQ == ck1.a) {
            DebugProbesKt.probeCoroutineSuspended(continuation);
        }
        return objQ;
    }

    @pq6
    @r15
    public static final <T> Object awaitNullable(@kp6 Call<T> call, @kp6 Continuation<? super T> continuation) {
        final ts0 ts0Var = new ts0(1, dr4.d(continuation));
        ts0Var.t(new KotlinExtensions$await$$inlined$suspendCancellableCoroutine$lambda$2(call));
        call.enqueue(new Callback<T>() { // from class: retrofit2.KotlinExtensions$await$4$2
            @Override // retrofit2.Callback
            public void onFailure(@kp6 Call<T> call2, @kp6 Throwable t) {
                cr4.h(call2, "call");
                cr4.h(t, "t");
                ts0Var.resumeWith(s38.a(t));
            }

            @Override // retrofit2.Callback
            public void onResponse(@kp6 Call<T> call2, @kp6 Response<T> response) {
                cr4.h(call2, "call");
                cr4.h(response, "response");
                if (response.isSuccessful()) {
                    ts0Var.resumeWith(response.body());
                } else {
                    ts0Var.resumeWith(s38.a(new HttpException(response)));
                }
            }
        });
        Object objQ = ts0Var.q();
        if (objQ == ck1.a) {
            DebugProbesKt.probeCoroutineSuspended(continuation);
        }
        return objQ;
    }

    @pq6
    public static final <T> Object awaitResponse(@kp6 Call<T> call, @kp6 Continuation<? super Response<T>> continuation) {
        final ts0 ts0Var = new ts0(1, dr4.d(continuation));
        ts0Var.t(new KotlinExtensions$awaitResponse$$inlined$suspendCancellableCoroutine$lambda$1(call));
        call.enqueue(new Callback<T>() { // from class: retrofit2.KotlinExtensions$awaitResponse$2$2
            @Override // retrofit2.Callback
            public void onFailure(@kp6 Call<T> call2, @kp6 Throwable t) {
                cr4.h(call2, "call");
                cr4.h(t, "t");
                ts0Var.resumeWith(s38.a(t));
            }

            @Override // retrofit2.Callback
            public void onResponse(@kp6 Call<T> call2, @kp6 Response<T> response) {
                cr4.h(call2, "call");
                cr4.h(response, "response");
                ts0Var.resumeWith(response);
            }
        });
        Object objQ = ts0Var.q();
        if (objQ == ck1.a) {
            DebugProbesKt.probeCoroutineSuspended(continuation);
        }
        return objQ;
    }

    public static final <T> T create(@kp6 Retrofit retrofit) {
        cr4.h(retrofit, "$this$create");
        cr4.m();
        throw null;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    @pq6
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object suspendAndThrow(@kp6 final Exception exc, @kp6 Continuation<?> continuation) {
        final AnonymousClass1 anonymousClass1;
        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 obj = anonymousClass1.result;
        ck1 ck1Var = ck1.a;
        int i2 = anonymousClass1.label;
        if (i2 != 0) {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
            return e6a.a;
        }
        s38.b(obj);
        anonymousClass1.L$0 = exc;
        anonymousClass1.label = 1;
        sc2.a.as(anonymousClass1.getB(), new Runnable() { // from class: retrofit2.KotlinExtensions$suspendAndThrow$$inlined$suspendCoroutineUninterceptedOrReturn$lambda$1
            @Override // java.lang.Runnable
            public final void run() {
                dr4.d(anonymousClass1).resumeWith(s38.a(exc));
            }
        });
        DebugProbesKt.probeCoroutineSuspended(anonymousClass1);
        return ck1Var;
    }
}
