package retrofit2; import com.google.common.net.HttpHeaders; import java.io.IOException; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.Iterator; import java.util.Map; import java.util.Objects; import okhttp3.MultipartBody; import okhttp3.RequestBody; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public abstract class ParameterHandler { /* JADX INFO: Access modifiers changed from: package-private */ public abstract void apply(RequestBuilder requestBuilder, T t) throws IOException; ParameterHandler() { } /* JADX INFO: Access modifiers changed from: package-private */ public final ParameterHandler> iterable() { return new ParameterHandler>(this) { // from class: retrofit2.ParameterHandler.1 final ParameterHandler this$0; { this.this$0 = this; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // retrofit2.ParameterHandler public void apply(RequestBuilder requestBuilder, Iterable iterable) throws IOException { if (iterable == null) { return; } Iterator it = iterable.iterator(); while (it.hasNext()) { this.this$0.apply(requestBuilder, it.next()); } } }; } /* JADX INFO: Access modifiers changed from: package-private */ public final ParameterHandler array() { return new ParameterHandler(this) { // from class: retrofit2.ParameterHandler.2 final ParameterHandler this$0; { this.this$0 = this; } /* JADX WARN: Multi-variable type inference failed */ @Override // retrofit2.ParameterHandler void apply(RequestBuilder requestBuilder, Object obj) throws IOException { if (obj == null) { return; } int length = Array.getLength(obj); for (int i = 0; i < length; i++) { this.this$0.apply(requestBuilder, Array.get(obj, i)); } } }; } /* loaded from: classes.dex */ static final class RelativeUrl extends ParameterHandler { private final Method method; private final int p; /* JADX INFO: Access modifiers changed from: package-private */ public RelativeUrl(Method method, int i) { this.method = method; this.p = i; } @Override // retrofit2.ParameterHandler final void apply(RequestBuilder requestBuilder, Object obj) { if (obj == null) { throw Utils.parameterError(this.method, this.p, "@Url parameter is null.", new Object[0]); } requestBuilder.setRelativeUrl(obj); } } /* loaded from: classes.dex */ static final class Header extends ParameterHandler { private final String name; private final Converter valueConverter; /* JADX INFO: Access modifiers changed from: package-private */ public Header(String str, Converter converter) { this.name = (String) Objects.requireNonNull(str, "name == null"); this.valueConverter = converter; } @Override // retrofit2.ParameterHandler final void apply(RequestBuilder requestBuilder, T t) throws IOException { String convert; if (t == null || (convert = this.valueConverter.convert(t)) == null) { return; } requestBuilder.addHeader(this.name, convert); } } /* loaded from: classes.dex */ static final class Path extends ParameterHandler { private final boolean encoded; private final Method method; private final String name; private final int p; private final Converter valueConverter; /* JADX INFO: Access modifiers changed from: package-private */ public Path(Method method, int i, String str, Converter converter, boolean z) { this.method = method; this.p = i; this.name = (String) Objects.requireNonNull(str, "name == null"); this.valueConverter = converter; this.encoded = z; } @Override // retrofit2.ParameterHandler final void apply(RequestBuilder requestBuilder, T t) throws IOException { if (t == null) { Method method = this.method; int i = this.p; StringBuilder sb = new StringBuilder("Path parameter \""); sb.append(this.name); sb.append("\" value must not be null."); throw Utils.parameterError(method, i, sb.toString(), new Object[0]); } requestBuilder.addPathParam(this.name, this.valueConverter.convert(t), this.encoded); } } /* loaded from: classes.dex */ static final class Query extends ParameterHandler { private final boolean encoded; private final String name; private final Converter valueConverter; /* JADX INFO: Access modifiers changed from: package-private */ public Query(String str, Converter converter, boolean z) { this.name = (String) Objects.requireNonNull(str, "name == null"); this.valueConverter = converter; this.encoded = z; } @Override // retrofit2.ParameterHandler final void apply(RequestBuilder requestBuilder, T t) throws IOException { String convert; if (t == null || (convert = this.valueConverter.convert(t)) == null) { return; } requestBuilder.addQueryParam(this.name, convert, this.encoded); } } /* loaded from: classes.dex */ static final class QueryName extends ParameterHandler { private final boolean encoded; private final Converter nameConverter; /* JADX INFO: Access modifiers changed from: package-private */ public QueryName(Converter converter, boolean z) { this.nameConverter = converter; this.encoded = z; } @Override // retrofit2.ParameterHandler final void apply(RequestBuilder requestBuilder, T t) throws IOException { if (t == null) { return; } requestBuilder.addQueryParam(this.nameConverter.convert(t), null, this.encoded); } } /* loaded from: classes.dex */ static final class QueryMap extends ParameterHandler> { private final boolean encoded; private final Method method; private final int p; private final Converter valueConverter; /* JADX INFO: Access modifiers changed from: package-private */ public QueryMap(Method method, int i, Converter converter, boolean z) { this.method = method; this.p = i; this.valueConverter = converter; this.encoded = z; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // retrofit2.ParameterHandler public final void apply(RequestBuilder requestBuilder, Map map) throws IOException { if (map == null) { throw Utils.parameterError(this.method, this.p, "Query map was null", new Object[0]); } for (Map.Entry entry : map.entrySet()) { String key = entry.getKey(); if (key == null) { throw Utils.parameterError(this.method, this.p, "Query map contained null key.", new Object[0]); } T value = entry.getValue(); if (value == null) { Method method = this.method; int i = this.p; StringBuilder sb = new StringBuilder("Query map contained null value for key '"); sb.append(key); sb.append("'."); throw Utils.parameterError(method, i, sb.toString(), new Object[0]); } String convert = this.valueConverter.convert(value); if (convert == null) { Method method2 = this.method; int i2 = this.p; StringBuilder sb2 = new StringBuilder("Query map value '"); sb2.append(value); sb2.append("' converted to null by "); sb2.append(this.valueConverter.getClass().getName()); sb2.append(" for key '"); sb2.append(key); sb2.append("'."); throw Utils.parameterError(method2, i2, sb2.toString(), new Object[0]); } requestBuilder.addQueryParam(key, convert, this.encoded); } } } /* loaded from: classes.dex */ static final class HeaderMap extends ParameterHandler> { private final Method method; private final int p; private final Converter valueConverter; /* JADX INFO: Access modifiers changed from: package-private */ public HeaderMap(Method method, int i, Converter converter) { this.method = method; this.p = i; this.valueConverter = converter; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // retrofit2.ParameterHandler public final void apply(RequestBuilder requestBuilder, Map map) throws IOException { if (map == null) { throw Utils.parameterError(this.method, this.p, "Header map was null.", new Object[0]); } for (Map.Entry entry : map.entrySet()) { String key = entry.getKey(); if (key == null) { throw Utils.parameterError(this.method, this.p, "Header map contained null key.", new Object[0]); } T value = entry.getValue(); if (value == null) { Method method = this.method; int i = this.p; StringBuilder sb = new StringBuilder("Header map contained null value for key '"); sb.append(key); sb.append("'."); throw Utils.parameterError(method, i, sb.toString(), new Object[0]); } requestBuilder.addHeader(key, this.valueConverter.convert(value)); } } } /* loaded from: classes.dex */ static final class Headers extends ParameterHandler { private final Method method; private final int p; /* JADX INFO: Access modifiers changed from: package-private */ public Headers(Method method, int i) { this.method = method; this.p = i; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // retrofit2.ParameterHandler public final void apply(RequestBuilder requestBuilder, okhttp3.Headers headers) { if (headers == null) { throw Utils.parameterError(this.method, this.p, "Headers parameter must not be null.", new Object[0]); } requestBuilder.addHeaders(headers); } } /* loaded from: classes.dex */ static final class Field extends ParameterHandler { private final boolean encoded; private final String name; private final Converter valueConverter; /* JADX INFO: Access modifiers changed from: package-private */ public Field(String str, Converter converter, boolean z) { this.name = (String) Objects.requireNonNull(str, "name == null"); this.valueConverter = converter; this.encoded = z; } @Override // retrofit2.ParameterHandler final void apply(RequestBuilder requestBuilder, T t) throws IOException { String convert; if (t == null || (convert = this.valueConverter.convert(t)) == null) { return; } requestBuilder.addFormField(this.name, convert, this.encoded); } } /* loaded from: classes.dex */ static final class FieldMap extends ParameterHandler> { private final boolean encoded; private final Method method; private final int p; private final Converter valueConverter; /* JADX INFO: Access modifiers changed from: package-private */ public FieldMap(Method method, int i, Converter converter, boolean z) { this.method = method; this.p = i; this.valueConverter = converter; this.encoded = z; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // retrofit2.ParameterHandler public final void apply(RequestBuilder requestBuilder, Map map) throws IOException { if (map == null) { throw Utils.parameterError(this.method, this.p, "Field map was null.", new Object[0]); } for (Map.Entry entry : map.entrySet()) { String key = entry.getKey(); if (key == null) { throw Utils.parameterError(this.method, this.p, "Field map contained null key.", new Object[0]); } T value = entry.getValue(); if (value == null) { Method method = this.method; int i = this.p; StringBuilder sb = new StringBuilder("Field map contained null value for key '"); sb.append(key); sb.append("'."); throw Utils.parameterError(method, i, sb.toString(), new Object[0]); } String convert = this.valueConverter.convert(value); if (convert == null) { Method method2 = this.method; int i2 = this.p; StringBuilder sb2 = new StringBuilder("Field map value '"); sb2.append(value); sb2.append("' converted to null by "); sb2.append(this.valueConverter.getClass().getName()); sb2.append(" for key '"); sb2.append(key); sb2.append("'."); throw Utils.parameterError(method2, i2, sb2.toString(), new Object[0]); } requestBuilder.addFormField(key, convert, this.encoded); } } } /* loaded from: classes.dex */ static final class Part extends ParameterHandler { private final Converter converter; private final okhttp3.Headers headers; private final Method method; private final int p; /* JADX INFO: Access modifiers changed from: package-private */ public Part(Method method, int i, okhttp3.Headers headers, Converter converter) { this.method = method; this.p = i; this.headers = headers; this.converter = converter; } @Override // retrofit2.ParameterHandler final void apply(RequestBuilder requestBuilder, T t) { if (t == null) { return; } try { requestBuilder.addPart(this.headers, this.converter.convert(t)); } catch (IOException e) { Method method = this.method; int i = this.p; StringBuilder sb = new StringBuilder("Unable to convert "); sb.append(t); sb.append(" to RequestBody"); throw Utils.parameterError(method, i, sb.toString(), e); } } } /* loaded from: classes.dex */ static final class RawPart extends ParameterHandler { static final RawPart INSTANCE = new RawPart(); private RawPart() { } /* JADX INFO: Access modifiers changed from: package-private */ @Override // retrofit2.ParameterHandler public final void apply(RequestBuilder requestBuilder, MultipartBody.Part part) { if (part != null) { requestBuilder.addPart(part); } } } /* loaded from: classes.dex */ static final class PartMap extends ParameterHandler> { private final Method method; private final int p; private final String transferEncoding; private final Converter valueConverter; /* JADX INFO: Access modifiers changed from: package-private */ public PartMap(Method method, int i, Converter converter, String str) { this.method = method; this.p = i; this.valueConverter = converter; this.transferEncoding = str; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // retrofit2.ParameterHandler public final void apply(RequestBuilder requestBuilder, Map map) throws IOException { if (map == null) { throw Utils.parameterError(this.method, this.p, "Part map was null.", new Object[0]); } for (Map.Entry entry : map.entrySet()) { String key = entry.getKey(); if (key == null) { throw Utils.parameterError(this.method, this.p, "Part map contained null key.", new Object[0]); } T value = entry.getValue(); if (value == null) { Method method = this.method; int i = this.p; StringBuilder sb = new StringBuilder("Part map contained null value for key '"); sb.append(key); sb.append("'."); throw Utils.parameterError(method, i, sb.toString(), new Object[0]); } StringBuilder sb2 = new StringBuilder("form-data; name=\""); sb2.append(key); sb2.append("\""); requestBuilder.addPart(okhttp3.Headers.of(HttpHeaders.CONTENT_DISPOSITION, sb2.toString(), "Content-Transfer-Encoding", this.transferEncoding), this.valueConverter.convert(value)); } } } /* loaded from: classes.dex */ static final class Body extends ParameterHandler { private final Converter converter; private final Method method; private final int p; /* JADX INFO: Access modifiers changed from: package-private */ public Body(Method method, int i, Converter converter) { this.method = method; this.p = i; this.converter = converter; } @Override // retrofit2.ParameterHandler final void apply(RequestBuilder requestBuilder, T t) { if (t == null) { throw Utils.parameterError(this.method, this.p, "Body parameter value must not be null.", new Object[0]); } try { requestBuilder.setBody(this.converter.convert(t)); } catch (IOException e) { Method method = this.method; int i = this.p; StringBuilder sb = new StringBuilder("Unable to convert "); sb.append(t); sb.append(" to RequestBody"); throw Utils.parameterError(method, e, i, sb.toString(), new Object[0]); } } } /* loaded from: classes.dex */ static final class Tag extends ParameterHandler { final Class cls; /* JADX INFO: Access modifiers changed from: package-private */ public Tag(Class cls) { this.cls = cls; } @Override // retrofit2.ParameterHandler final void apply(RequestBuilder requestBuilder, T t) { requestBuilder.addTag(this.cls, t); } } }