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<?>> f6881a = new ConcurrentHashMap();

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

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

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

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

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

    public static final class a {

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

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

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

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

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

        public a() {
            y yVar = y.f7014a;
            this.f6890d = new ArrayList();
            this.f6891e = new ArrayList();
            this.f6887a = 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.f6445g.get(r0.size() - 1))) {
                this.f6889c = sVarA;
                return this;
            }
            throw new IllegalArgumentException("baseUrl must end in /: " + sVarA);
        }

        public d0 b() {
            if (this.f6889c == null) {
                throw new IllegalStateException("Base URL required.");
            }
            d.a wVar = this.f6888b;
            if (wVar == null) {
                wVar = new g.w(new w.b());
            }
            d.a aVar = wVar;
            Executor executorB = this.f6887a.b();
            ArrayList arrayList = new ArrayList(this.f6891e);
            arrayList.addAll(this.f6887a.a(executorB));
            ArrayList arrayList2 = new ArrayList(this.f6887a.d() + this.f6890d.size() + 1);
            arrayList2.add(new j.a());
            arrayList2.addAll(this.f6890d);
            arrayList2.addAll(this.f6887a.c());
            return new d0(aVar, this.f6889c, 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.f6882b = aVar;
        this.f6883c = sVar;
        this.f6884d = list;
        this.f6885e = list2;
        this.f6886f = z;
    }

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

    public e0<?> b(Method method) {
        e0<?> e0VarB;
        e0<?> e0Var = this.f6881a.get(method);
        if (e0Var != null) {
            return e0Var;
        }
        synchronized (this.f6881a) {
            e0VarB = this.f6881a.get(method);
            if (e0VarB == null) {
                e0VarB = e0.b(this, method);
                this.f6881a.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.f6884d.indexOf(null) + 1;
        int size = this.f6884d.size();
        for (int i2 = iIndexOf; i2 < size; i2++) {
            j<T, g.c0> jVar = (j<T, g.c0>) this.f6884d.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.f6884d.size();
        while (iIndexOf < size2) {
            sb.append("\n   * ");
            sb.append(this.f6884d.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.f6884d.indexOf(null) + 1;
        int size = this.f6884d.size();
        for (int i2 = iIndexOf; i2 < size; i2++) {
            j<g.f0, T> jVar = (j<g.f0, T>) this.f6884d.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.f6884d.size();
        while (iIndexOf < size2) {
            sb.append("\n   * ");
            sb.append(this.f6884d.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.f6884d.size();
        for (int i2 = 0; i2 < size; i2++) {
            Objects.requireNonNull(this.f6884d.get(i2));
        }
        return a.d.f6852a;
    }
}
