package f;

import f.e;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nullable;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;

/* JADX INFO: compiled from: CompletableFutureCallAdapterFactory.java */
/* JADX INFO: loaded from: classes.dex */
@IgnoreJRERequirement
final class g extends e.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    static final e.a f1637a = new g();

    /* JADX INFO: compiled from: CompletableFutureCallAdapterFactory.java */
    @IgnoreJRERequirement
    private static final class a<R> implements e<R, CompletableFuture<R>> {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final Type f1638a;

        /* JADX INFO: renamed from: f.g$a$a, reason: collision with other inner class name */
        /* JADX INFO: compiled from: CompletableFutureCallAdapterFactory.java */
        @IgnoreJRERequirement
        private class C0038a implements f<R> {

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            private final CompletableFuture<R> f1639b;

            public C0038a(a aVar, CompletableFuture<R> completableFuture) {
                this.f1639b = completableFuture;
            }

            @Override // f.f
            public void a(d<R> dVar, Throwable th) {
                this.f1639b.completeExceptionally(th);
            }

            @Override // f.f
            public void b(d<R> dVar, t<R> tVar) {
                if (tVar.d()) {
                    this.f1639b.complete(tVar.a());
                } else {
                    this.f1639b.completeExceptionally(new j(tVar));
                }
            }
        }

        a(Type type) {
            this.f1638a = type;
        }

        @Override // f.e
        public Type a() {
            return this.f1638a;
        }

        @Override // f.e
        /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
        public CompletableFuture<R> b(d<R> dVar) {
            b bVar = new b(dVar);
            dVar.v(new C0038a(this, bVar));
            return bVar;
        }
    }

    /* JADX INFO: compiled from: CompletableFutureCallAdapterFactory.java */
    @IgnoreJRERequirement
    private static final class b<T> extends CompletableFuture<T> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final d<?> f1640b;

        b(d<?> dVar) {
            this.f1640b = dVar;
        }

        @Override // java.util.concurrent.CompletableFuture, java.util.concurrent.Future
        public boolean cancel(boolean z) {
            if (z) {
                this.f1640b.cancel();
            }
            return super.cancel(z);
        }
    }

    /* JADX INFO: compiled from: CompletableFutureCallAdapterFactory.java */
    @IgnoreJRERequirement
    private static final class c<R> implements e<R, CompletableFuture<t<R>>> {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final Type f1641a;

        /* JADX INFO: compiled from: CompletableFutureCallAdapterFactory.java */
        @IgnoreJRERequirement
        private class a implements f<R> {

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            private final CompletableFuture<t<R>> f1642b;

            public a(c cVar, CompletableFuture<t<R>> completableFuture) {
                this.f1642b = completableFuture;
            }

            @Override // f.f
            public void a(d<R> dVar, Throwable th) {
                this.f1642b.completeExceptionally(th);
            }

            @Override // f.f
            public void b(d<R> dVar, t<R> tVar) {
                this.f1642b.complete(tVar);
            }
        }

        c(Type type) {
            this.f1641a = type;
        }

        @Override // f.e
        public Type a() {
            return this.f1641a;
        }

        @Override // f.e
        /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
        public CompletableFuture<t<R>> b(d<R> dVar) {
            b bVar = new b(dVar);
            dVar.v(new a(this, bVar));
            return bVar;
        }
    }

    g() {
    }

    @Override // f.e.a
    @Nullable
    public e<?, ?> a(Type type, Annotation[] annotationArr, u uVar) {
        if (e.a.c(type) != CompletableFuture.class) {
            return null;
        }
        if (!(type instanceof ParameterizedType)) {
            throw new IllegalStateException("CompletableFuture return type must be parameterized as CompletableFuture<Foo> or CompletableFuture<? extends Foo>");
        }
        Type typeB = e.a.b(0, (ParameterizedType) type);
        if (e.a.c(typeB) != t.class) {
            return new a(typeB);
        }
        if (typeB instanceof ParameterizedType) {
            return new c(e.a.b(0, (ParameterizedType) typeB));
        }
        throw new IllegalStateException("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
}
