package l;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;
import l.a;
import l.c;
import l.j;
import okhttp3.Call;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/* JADX INFO: compiled from: Retrofit.java */
/* JADX INFO: loaded from: classes.dex */
public final class c0 {
    public final Map<Method, d0<?>> a = new ConcurrentHashMap();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Call.Factory f4998b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final HttpUrl f4999c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final List<j.a> f5000d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final List<c.a> f5001e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final boolean f5002f;

    /* JADX INFO: compiled from: Retrofit.java */
    public class a implements InvocationHandler {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final y f5003b = y.a;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public final Object[] f5004e = new Object[0];

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public final /* synthetic */ Class f5005f;

        public a(Class cls) {
            this.f5005f = cls;
        }

        @Override // java.lang.reflect.InvocationHandler
        @Nullable
        public Object invoke(Object obj, Method method, @Nullable Object[] objArr) throws Throwable {
            if (method.getDeclaringClass() == Object.class) {
                return method.invoke(this, objArr);
            }
            if (this.f5003b.f(method)) {
                return this.f5003b.e(method, this.f5005f, obj, objArr);
            }
            d0<?> d0VarC = c0.this.c(method);
            if (objArr == null) {
                objArr = this.f5004e;
            }
            return d0VarC.a(objArr);
        }
    }

    /* JADX INFO: compiled from: Retrofit.java */
    public static final class b {
        public final y a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        @Nullable
        public Call.Factory f5007b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        @Nullable
        public HttpUrl f5008c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public final List<j.a> f5009d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public final List<c.a> f5010e;

        public b() {
            y yVar = y.a;
            this.f5009d = new ArrayList();
            this.f5010e = new ArrayList();
            this.a = yVar;
        }

        public b a(String str) {
            Objects.requireNonNull(str, "baseUrl == null");
            HttpUrl httpUrl = HttpUrl.get(str);
            Objects.requireNonNull(httpUrl, "baseUrl == null");
            if ("".equals(httpUrl.pathSegments().get(r0.size() - 1))) {
                this.f5008c = httpUrl;
                return this;
            }
            throw new IllegalArgumentException("baseUrl must end in /: " + httpUrl);
        }

        public c0 b() {
            if (this.f5008c == null) {
                throw new IllegalStateException("Base URL required.");
            }
            Call.Factory okHttpClient = this.f5007b;
            if (okHttpClient == null) {
                okHttpClient = new OkHttpClient();
            }
            Call.Factory factory = okHttpClient;
            Executor executorB = this.a.b();
            ArrayList arrayList = new ArrayList(this.f5010e);
            arrayList.addAll(this.a.a(executorB));
            ArrayList arrayList2 = new ArrayList(this.a.d() + this.f5009d.size() + 1);
            arrayList2.add(new l.a());
            arrayList2.addAll(this.f5009d);
            arrayList2.addAll(this.a.c());
            return new c0(factory, this.f5008c, Collections.unmodifiableList(arrayList2), Collections.unmodifiableList(arrayList), executorB, false);
        }
    }

    public c0(Call.Factory factory, HttpUrl httpUrl, List<j.a> list, List<c.a> list2, @Nullable Executor executor, boolean z) {
        this.f4998b = factory;
        this.f4999c = httpUrl;
        this.f5000d = list;
        this.f5001e = list2;
        this.f5002f = z;
    }

    public c<?, ?> a(Type type, Annotation[] annotationArr) {
        Objects.requireNonNull(type, "returnType == null");
        Objects.requireNonNull(annotationArr, "annotations == null");
        int iIndexOf = this.f5001e.indexOf(null) + 1;
        int size = this.f5001e.size();
        for (int i2 = iIndexOf; i2 < size; i2++) {
            c<?, ?> cVarA = this.f5001e.get(i2).a(type, annotationArr, this);
            if (cVarA != null) {
                return cVarA;
            }
        }
        StringBuilder sb = new StringBuilder("Could not locate call adapter for ");
        sb.append(type);
        sb.append(".\n");
        sb.append("  Tried:");
        int size2 = this.f5001e.size();
        while (iIndexOf < size2) {
            sb.append("\n   * ");
            sb.append(this.f5001e.get(iIndexOf).getClass().getName());
            iIndexOf++;
        }
        throw new IllegalArgumentException(sb.toString());
    }

    public <T> T b(Class<T> cls) {
        if (!cls.isInterface()) {
            throw new IllegalArgumentException("API declarations must be interfaces.");
        }
        if (cls.getInterfaces().length > 0) {
            throw new IllegalArgumentException("API interfaces must not extend other interfaces.");
        }
        if (this.f5002f) {
            y yVar = y.a;
            for (Method method : cls.getDeclaredMethods()) {
                if (!yVar.f(method) && !Modifier.isStatic(method.getModifiers())) {
                    c(method);
                }
            }
        }
        return (T) Proxy.newProxyInstance(cls.getClassLoader(), new Class[]{cls}, new a(cls));
    }

    public d0<?> c(Method method) {
        d0<?> d0VarB;
        d0<?> d0Var = this.a.get(method);
        if (d0Var != null) {
            return d0Var;
        }
        synchronized (this.a) {
            d0VarB = this.a.get(method);
            if (d0VarB == null) {
                d0VarB = d0.b(this, method);
                this.a.put(method, d0VarB);
            }
        }
        return d0VarB;
    }

    public <T> j<T, RequestBody> d(Type type, Annotation[] annotationArr, Annotation[] annotationArr2) {
        Objects.requireNonNull(type, "type == null");
        Objects.requireNonNull(annotationArr, "parameterAnnotations == null");
        Objects.requireNonNull(annotationArr2, "methodAnnotations == null");
        int iIndexOf = this.f5000d.indexOf(null) + 1;
        int size = this.f5000d.size();
        for (int i2 = iIndexOf; i2 < size; i2++) {
            j<T, RequestBody> jVar = (j<T, RequestBody>) this.f5000d.get(i2).a(type, annotationArr, annotationArr2, this);
            if (jVar != null) {
                return jVar;
            }
        }
        StringBuilder sb = new StringBuilder("Could not locate RequestBody converter for ");
        sb.append(type);
        sb.append(".\n");
        sb.append("  Tried:");
        int size2 = this.f5000d.size();
        while (iIndexOf < size2) {
            sb.append("\n   * ");
            sb.append(this.f5000d.get(iIndexOf).getClass().getName());
            iIndexOf++;
        }
        throw new IllegalArgumentException(sb.toString());
    }

    public <T> j<ResponseBody, T> e(Type type, Annotation[] annotationArr) {
        Objects.requireNonNull(type, "type == null");
        Objects.requireNonNull(annotationArr, "annotations == null");
        int iIndexOf = this.f5000d.indexOf(null) + 1;
        int size = this.f5000d.size();
        for (int i2 = iIndexOf; i2 < size; i2++) {
            j<ResponseBody, T> jVar = (j<ResponseBody, T>) this.f5000d.get(i2).b(type, annotationArr, this);
            if (jVar != null) {
                return jVar;
            }
        }
        StringBuilder sb = new StringBuilder("Could not locate ResponseBody converter for ");
        sb.append(type);
        sb.append(".\n");
        sb.append("  Tried:");
        int size2 = this.f5000d.size();
        while (iIndexOf < size2) {
            sb.append("\n   * ");
            sb.append(this.f5000d.get(iIndexOf).getClass().getName());
            iIndexOf++;
        }
        throw new IllegalArgumentException(sb.toString());
    }

    public <T> j<T, String> f(Type type, Annotation[] annotationArr) {
        Objects.requireNonNull(type, "type == null");
        Objects.requireNonNull(annotationArr, "annotations == null");
        int size = this.f5000d.size();
        for (int i2 = 0; i2 < size; i2++) {
            Objects.requireNonNull(this.f5000d.get(i2));
        }
        return a.d.a;
    }
}
