package j;

import g.d;
import g.s;
import g.w;
import j.a;
import j.c;
import j.j;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
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;

/* JADX INFO: loaded from: classes.dex */
public final class d0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Map<Method, e0<?>> f6895a = new ConcurrentHashMap();

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final g.s f6897c;

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

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

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

    public static final class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final y f6901a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        @Nullable
        public d.a f6902b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        @Nullable
        public g.s f6903c;

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

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

        public a() {
            y yVar = y.f7028a;
            this.f6904d = new ArrayList();
            this.f6905e = new ArrayList();
            this.f6901a = yVar;
        }

        public a a(String str) {
            Objects.requireNonNull(str, "baseUrl == null");
            s.a aVar = new s.a();
            aVar.c(null, str);
            g.s sVarA = aVar.a();
            if ("".equals(sVarA.f6459g.get(r0.size() - 1))) {
                this.f6903c = sVarA;
                return this;
            }
            throw new IllegalArgumentException("baseUrl must end in /: " + sVarA);
        }

        public d0 b() {
            if (this.f6903c == null) {
                throw new IllegalStateException("Base URL required.");
            }
            d.a wVar = this.f6902b;
            if (wVar == null) {
                wVar = new g.w(new w.b());
            }
            d.a aVar = wVar;
            Executor executorB = this.f6901a.b();
            ArrayList arrayList = new ArrayList(this.f6905e);
            arrayList.addAll(this.f6901a.a(executorB));
            ArrayList arrayList2 = new ArrayList(this.f6901a.d() + this.f6904d.size() + 1);
            arrayList2.add(new j.a());
            arrayList2.addAll(this.f6904d);
            arrayList2.addAll(this.f6901a.c());
            return new d0(aVar, this.f6903c, Collections.unmodifiableList(arrayList2), Collections.unmodifiableList(arrayList), executorB, false);
        }
    }

    public d0(d.a aVar, g.s sVar, List<j.a> list, List<c.a> list2, @Nullable Executor executor, boolean z) {
        this.f6896b = aVar;
        this.f6897c = sVar;
        this.f6898d = list;
        this.f6899e = list2;
        this.f6900f = z;
    }

    public c<?, ?> a(Type type, Annotation[] annotationArr) {
        Objects.requireNonNull(type, "returnType == null");
        Objects.requireNonNull(annotationArr, "annotations == null");
        int iIndexOf = this.f6899e.indexOf(null) + 1;
        int size = this.f6899e.size();
        for (int i2 = iIndexOf; i2 < size; i2++) {
            c<?, ?> cVarA = this.f6899e.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.f6899e.size();
        while (iIndexOf < size2) {
            sb.append("\n   * ");
            sb.append(this.f6899e.get(iIndexOf).getClass().getName());
            iIndexOf++;
        }
        throw new IllegalArgumentException(sb.toString());
    }

    public e0<?> b(Method method) {
        e0<?> e0VarB;
        e0<?> e0Var = this.f6895a.get(method);
        if (e0Var != null) {
            return e0Var;
        }
        synchronized (this.f6895a) {
            e0VarB = this.f6895a.get(method);
            if (e0VarB == null) {
                e0VarB = e0.b(this, method);
                this.f6895a.put(method, e0VarB);
            }
        }
        return e0VarB;
    }

    public <T> j<T, g.c0> c(Type type, Annotation[] annotationArr, Annotation[] annotationArr2) {
        Objects.requireNonNull(type, "type == null");
        Objects.requireNonNull(annotationArr, "parameterAnnotations == null");
        Objects.requireNonNull(annotationArr2, "methodAnnotations == null");
        int iIndexOf = this.f6898d.indexOf(null) + 1;
        int size = this.f6898d.size();
        for (int i2 = iIndexOf; i2 < size; i2++) {
            j<T, g.c0> jVar = (j<T, g.c0>) this.f6898d.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.f6898d.size();
        while (iIndexOf < size2) {
            sb.append("\n   * ");
            sb.append(this.f6898d.get(iIndexOf).getClass().getName());
            iIndexOf++;
        }
        throw new IllegalArgumentException(sb.toString());
    }

    public <T> j<g.f0, T> d(Type type, Annotation[] annotationArr) {
        Objects.requireNonNull(type, "type == null");
        Objects.requireNonNull(annotationArr, "annotations == null");
        int iIndexOf = this.f6898d.indexOf(null) + 1;
        int size = this.f6898d.size();
        for (int i2 = iIndexOf; i2 < size; i2++) {
            j<g.f0, T> jVar = (j<g.f0, T>) this.f6898d.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.f6898d.size();
        while (iIndexOf < size2) {
            sb.append("\n   * ");
            sb.append(this.f6898d.get(iIndexOf).getClass().getName());
            iIndexOf++;
        }
        throw new IllegalArgumentException(sb.toString());
    }

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