package retrofit2; import e3.InterfaceC0318d; import e3.O; import e3.T; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import kotlin.coroutines.Continuation; import retrofit2.Utils; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public abstract class HttpServiceMethod extends ServiceMethod { private final InterfaceC0318d callFactory; private final RequestFactory requestFactory; private final Converter responseConverter; /* loaded from: classes3.dex */ public static final class CallAdapted extends HttpServiceMethod { private final CallAdapter callAdapter; public CallAdapted(RequestFactory requestFactory, InterfaceC0318d interfaceC0318d, Converter converter, CallAdapter callAdapter) { super(requestFactory, interfaceC0318d, converter); this.callAdapter = callAdapter; } @Override // retrofit2.HttpServiceMethod public ReturnT adapt(Call call, Object[] objArr) { return this.callAdapter.adapt(call); } } /* loaded from: classes3.dex */ public static final class SuspendForBody extends HttpServiceMethod { private final CallAdapter> callAdapter; private final boolean isNullable; public SuspendForBody(RequestFactory requestFactory, InterfaceC0318d interfaceC0318d, Converter converter, CallAdapter> callAdapter, boolean z3) { super(requestFactory, interfaceC0318d, converter); this.callAdapter = callAdapter; this.isNullable = z3; } @Override // retrofit2.HttpServiceMethod public Object adapt(Call call, Object[] objArr) { Call adapt = this.callAdapter.adapt(call); Continuation continuation = (Continuation) objArr[objArr.length - 1]; try { return this.isNullable ? KotlinExtensions.awaitNullable(adapt, continuation) : KotlinExtensions.await(adapt, continuation); } catch (Exception e4) { return KotlinExtensions.suspendAndThrow(e4, continuation); } } } /* loaded from: classes3.dex */ public static final class SuspendForResponse extends HttpServiceMethod { private final CallAdapter> callAdapter; public SuspendForResponse(RequestFactory requestFactory, InterfaceC0318d interfaceC0318d, Converter converter, CallAdapter> callAdapter) { super(requestFactory, interfaceC0318d, converter); this.callAdapter = callAdapter; } @Override // retrofit2.HttpServiceMethod public Object adapt(Call call, Object[] objArr) { Call adapt = this.callAdapter.adapt(call); Continuation continuation = (Continuation) objArr[objArr.length - 1]; try { return KotlinExtensions.awaitResponse(adapt, continuation); } catch (Exception e4) { return KotlinExtensions.suspendAndThrow(e4, continuation); } } } public HttpServiceMethod(RequestFactory requestFactory, InterfaceC0318d interfaceC0318d, Converter converter) { this.requestFactory = requestFactory; this.callFactory = interfaceC0318d; this.responseConverter = converter; } private static CallAdapter createCallAdapter(Retrofit retrofit, Method method, Type type, Annotation[] annotationArr) { try { return (CallAdapter) retrofit.callAdapter(type, annotationArr); } catch (RuntimeException e4) { throw Utils.methodError(method, e4, "Unable to create call adapter for %s", type); } } private static Converter createResponseConverter(Retrofit retrofit, Method method, Type type) { try { return retrofit.responseBodyConverter(type, method.getAnnotations()); } catch (RuntimeException e4) { throw Utils.methodError(method, e4, "Unable to create converter for %s", type); } } public static HttpServiceMethod parseAnnotations(Retrofit retrofit, Method method, RequestFactory requestFactory) { Type genericReturnType; boolean z3; boolean z4 = requestFactory.isKotlinSuspendFunction; Annotation[] annotations = method.getAnnotations(); if (z4) { Type[] genericParameterTypes = method.getGenericParameterTypes(); Type parameterLowerBound = Utils.getParameterLowerBound(0, (ParameterizedType) genericParameterTypes[genericParameterTypes.length - 1]); if (Utils.getRawType(parameterLowerBound) == Response.class && (parameterLowerBound instanceof ParameterizedType)) { parameterLowerBound = Utils.getParameterUpperBound(0, (ParameterizedType) parameterLowerBound); z3 = true; } else { z3 = false; } genericReturnType = new Utils.ParameterizedTypeImpl(null, Call.class, parameterLowerBound); annotations = SkipCallbackExecutorImpl.ensurePresent(annotations); } else { genericReturnType = method.getGenericReturnType(); z3 = false; } CallAdapter createCallAdapter = createCallAdapter(retrofit, method, genericReturnType, annotations); Type responseType = createCallAdapter.responseType(); if (responseType == O.class) { throw Utils.methodError(method, "'" + Utils.getRawType(responseType).getName() + "' is not a valid response body type. Did you mean ResponseBody?", new Object[0]); } if (responseType == Response.class) { throw Utils.methodError(method, "Response must include generic type (e.g., Response)", new Object[0]); } if (requestFactory.httpMethod.equals("HEAD") && !Void.class.equals(responseType)) { throw Utils.methodError(method, "HEAD method must use Void as response type.", new Object[0]); } Converter createResponseConverter = createResponseConverter(retrofit, method, responseType); InterfaceC0318d interfaceC0318d = retrofit.callFactory; return !z4 ? new CallAdapted(requestFactory, interfaceC0318d, createResponseConverter, createCallAdapter) : z3 ? new SuspendForResponse(requestFactory, interfaceC0318d, createResponseConverter, createCallAdapter) : new SuspendForBody(requestFactory, interfaceC0318d, createResponseConverter, createCallAdapter, false); } public abstract ReturnT adapt(Call call, Object[] objArr); @Override // retrofit2.ServiceMethod public final ReturnT invoke(Object[] objArr) { return adapt(new OkHttpCall(this.requestFactory, objArr, this.callFactory, this.responseConverter), objArr); } }