package or;

import com.google.firebase.perf.FirebasePerformance;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import or.y;
import uq.d0;
import uq.e;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes5.dex */
public abstract class k extends v {

    /* renamed from: a, reason: collision with root package name */
    private final s f31674a;

    /* renamed from: b, reason: collision with root package name */
    private final e.a f31675b;

    /* renamed from: c, reason: collision with root package name */
    private final f f31676c;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes5.dex */
    public static final class a extends k {

        /* renamed from: d, reason: collision with root package name */
        private final or.c f31677d;

        a(s sVar, e.a aVar, f fVar, or.c cVar) {
            super(sVar, aVar, fVar);
            this.f31677d = cVar;
        }

        @Override // or.k
        protected Object c(or.b bVar, Object[] objArr) {
            return this.f31677d.a(bVar);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes5.dex */
    public static final class b extends k {

        /* renamed from: d, reason: collision with root package name */
        private final or.c f31678d;

        /* renamed from: e, reason: collision with root package name */
        private final boolean f31679e;

        b(s sVar, e.a aVar, f fVar, or.c cVar, boolean z10) {
            super(sVar, aVar, fVar);
            this.f31678d = cVar;
            this.f31679e = z10;
        }

        @Override // or.k
        protected Object c(or.b bVar, Object[] objArr) {
            or.b bVar2 = (or.b) this.f31678d.a(bVar);
            vm.d dVar = (vm.d) objArr[objArr.length - 1];
            try {
                return this.f31679e ? m.b(bVar2, dVar) : m.a(bVar2, dVar);
            } catch (Exception e10) {
                return m.d(e10, dVar);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes5.dex */
    public static final class c extends k {

        /* renamed from: d, reason: collision with root package name */
        private final or.c f31680d;

        c(s sVar, e.a aVar, f fVar, or.c cVar) {
            super(sVar, aVar, fVar);
            this.f31680d = cVar;
        }

        @Override // or.k
        protected Object c(or.b bVar, Object[] objArr) {
            or.b bVar2 = (or.b) this.f31680d.a(bVar);
            vm.d dVar = (vm.d) objArr[objArr.length - 1];
            try {
                return m.c(bVar2, dVar);
            } catch (Exception e10) {
                return m.d(e10, dVar);
            }
        }
    }

    k(s sVar, e.a aVar, f fVar) {
        this.f31674a = sVar;
        this.f31675b = aVar;
        this.f31676c = fVar;
    }

    private static or.c d(u uVar, Method method, Type type, Annotation[] annotationArr) {
        try {
            return uVar.a(type, annotationArr);
        } catch (RuntimeException e10) {
            throw y.n(method, e10, "Unable to create call adapter for %s", type);
        }
    }

    private static f e(u uVar, Method method, Type type) {
        try {
            return uVar.h(type, method.getAnnotations());
        } catch (RuntimeException e10) {
            throw y.n(method, e10, "Unable to create converter for %s", type);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static k f(u uVar, Method method, s sVar) {
        Type genericReturnType;
        boolean z10;
        boolean z11 = sVar.f31786k;
        Annotation[] annotations = method.getAnnotations();
        if (z11) {
            Type[] genericParameterTypes = method.getGenericParameterTypes();
            Type f10 = y.f(0, (ParameterizedType) genericParameterTypes[genericParameterTypes.length - 1]);
            if (y.h(f10) == t.class && (f10 instanceof ParameterizedType)) {
                f10 = y.g(0, (ParameterizedType) f10);
                z10 = true;
            } else {
                z10 = false;
            }
            genericReturnType = new y.b(null, or.b.class, f10);
            annotations = x.a(annotations);
        } else {
            genericReturnType = method.getGenericReturnType();
            z10 = false;
        }
        or.c d10 = d(uVar, method, genericReturnType, annotations);
        Type b10 = d10.b();
        if (b10 == d0.class) {
            throw y.m(method, "'" + y.h(b10).getName() + "' is not a valid response body type. Did you mean ResponseBody?", new Object[0]);
        }
        if (b10 == t.class) {
            throw y.m(method, "Response must include generic type (e.g., Response<String>)", new Object[0]);
        }
        if (sVar.f31778c.equals(FirebasePerformance.HttpMethod.HEAD) && !Void.class.equals(b10)) {
            throw y.m(method, "HEAD method must use Void as response type.", new Object[0]);
        }
        f e10 = e(uVar, method, b10);
        e.a aVar = uVar.f31816b;
        return !z11 ? new a(sVar, aVar, e10, d10) : z10 ? new c(sVar, aVar, e10, d10) : new b(sVar, aVar, e10, d10, false);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    @Override // or.v
    public final Object a(Object[] objArr) {
        return c(new n(this.f31674a, objArr, this.f31675b, this.f31676c), objArr);
    }

    protected abstract Object c(or.b bVar, Object[] objArr);
}
