package retrofit2; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import o.InterfaceC14907gbi; import okhttp3.Call; import okhttp3.ResponseBody; import retrofit2.Utils; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public abstract class HttpServiceMethod extends ServiceMethod { private final Call.Factory callFactory; private final RequestFactory requestFactory; private final Converter responseConverter; protected abstract ReturnT adapt(Call call, Object[] objArr); /* JADX INFO: Access modifiers changed from: package-private */ public static HttpServiceMethod parseAnnotations(Retrofit retrofit, Method method, RequestFactory requestFactory) { Type genericReturnType; boolean z; boolean z2 = requestFactory.isKotlinSuspendFunction; Annotation[] annotations = method.getAnnotations(); if (z2) { Type[] genericParameterTypes = method.getGenericParameterTypes(); z = true; 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); } else { z = false; } genericReturnType = new Utils.ParameterizedTypeImpl(null, Call.class, parameterLowerBound); annotations = SkipCallbackExecutorImpl.ensurePresent(annotations); } else { genericReturnType = method.getGenericReturnType(); z = false; } CallAdapter createCallAdapter = createCallAdapter(retrofit, method, genericReturnType, annotations); Type responseType = createCallAdapter.responseType(); if (responseType == okhttp3.Response.class) { StringBuilder sb = new StringBuilder("'"); sb.append(Utils.getRawType(responseType).getName()); sb.append("' is not a valid response body type. Did you mean ResponseBody?"); throw Utils.methodError(method, sb.toString(), 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); Call.Factory factory = retrofit.callFactory; if (!z2) { return new CallAdapted(requestFactory, factory, createResponseConverter, createCallAdapter); } if (z) { return new SuspendForResponse(requestFactory, factory, createResponseConverter, createCallAdapter); } return new SuspendForBody(requestFactory, factory, createResponseConverter, createCallAdapter, false); } private static CallAdapter createCallAdapter(Retrofit retrofit, Method method, Type type, Annotation[] annotationArr) { try { return (CallAdapter) retrofit.callAdapter(type, annotationArr); } catch (RuntimeException e) { throw Utils.methodError(method, e, "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 e) { throw Utils.methodError(method, e, "Unable to create converter for %s", type); } } HttpServiceMethod(RequestFactory requestFactory, Call.Factory factory, Converter converter) { this.requestFactory = requestFactory; this.callFactory = factory; this.responseConverter = converter; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // retrofit2.ServiceMethod public final ReturnT invoke(Object[] objArr) { return adapt(new OkHttpCall(this.requestFactory, objArr, this.callFactory, this.responseConverter), objArr); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static final class CallAdapted extends HttpServiceMethod { private final CallAdapter callAdapter; CallAdapted(RequestFactory requestFactory, Call.Factory factory, Converter converter, CallAdapter callAdapter) { super(requestFactory, factory, converter); this.callAdapter = callAdapter; } @Override // retrofit2.HttpServiceMethod protected final ReturnT adapt(Call call, Object[] objArr) { return this.callAdapter.adapt(call); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static final class SuspendForResponse extends HttpServiceMethod { private final CallAdapter> callAdapter; SuspendForResponse(RequestFactory requestFactory, Call.Factory factory, Converter converter, CallAdapter> callAdapter) { super(requestFactory, factory, converter); this.callAdapter = callAdapter; } @Override // retrofit2.HttpServiceMethod protected final Object adapt(Call call, Object[] objArr) { Call adapt = this.callAdapter.adapt(call); InterfaceC14907gbi interfaceC14907gbi = (InterfaceC14907gbi) objArr[objArr.length - 1]; try { return KotlinExtensions.awaitResponse(adapt, interfaceC14907gbi); } catch (Exception e) { return KotlinExtensions.suspendAndThrow(e, interfaceC14907gbi); } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static final class SuspendForBody extends HttpServiceMethod { private final CallAdapter> callAdapter; private final boolean isNullable; SuspendForBody(RequestFactory requestFactory, Call.Factory factory, Converter converter, CallAdapter> callAdapter, boolean z) { super(requestFactory, factory, converter); this.callAdapter = callAdapter; this.isNullable = z; } @Override // retrofit2.HttpServiceMethod protected final Object adapt(Call call, Object[] objArr) { Call adapt = this.callAdapter.adapt(call); InterfaceC14907gbi interfaceC14907gbi = (InterfaceC14907gbi) objArr[objArr.length - 1]; try { if (this.isNullable) { return KotlinExtensions.awaitNullable(adapt, interfaceC14907gbi); } return KotlinExtensions.await(adapt, interfaceC14907gbi); } catch (Exception e) { return KotlinExtensions.suspendAndThrow(e, interfaceC14907gbi); } } } }