package or;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.concurrent.CompletableFuture;
import or.c;

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

    /* renamed from: a, reason: collision with root package name */
    static final c.a f31649a = new e();

    /* loaded from: classes5.dex */
    private static final class a implements or.c {

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

        /* JADX INFO: Access modifiers changed from: private */
        /* renamed from: or.e$a$a, reason: collision with other inner class name */
        /* loaded from: classes5.dex */
        public class C0730a implements d {

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

            public C0730a(CompletableFuture completableFuture) {
                this.f31651a = completableFuture;
            }

            @Override // or.d
            public void a(or.b bVar, Throwable th2) {
                this.f31651a.completeExceptionally(th2);
            }

            @Override // or.d
            public void b(or.b bVar, t tVar) {
                if (tVar.e()) {
                    this.f31651a.complete(tVar.a());
                } else {
                    this.f31651a.completeExceptionally(new j(tVar));
                }
            }
        }

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

        @Override // or.c
        public Type b() {
            return this.f31650a;
        }

        @Override // or.c
        /* renamed from: c, reason: merged with bridge method [inline-methods] */
        public CompletableFuture a(or.b bVar) {
            b bVar2 = new b(bVar);
            bVar.s0(new C0730a(bVar2));
            return bVar2;
        }
    }

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

        /* renamed from: p, reason: collision with root package name */
        private final or.b f31653p;

        b(or.b bVar) {
            this.f31653p = bVar;
        }

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

    /* loaded from: classes5.dex */
    private static final class c implements or.c {

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

        /* JADX INFO: Access modifiers changed from: private */
        /* loaded from: classes5.dex */
        public class a implements d {

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

            public a(CompletableFuture completableFuture) {
                this.f31655a = completableFuture;
            }

            @Override // or.d
            public void a(or.b bVar, Throwable th2) {
                this.f31655a.completeExceptionally(th2);
            }

            @Override // or.d
            public void b(or.b bVar, t tVar) {
                this.f31655a.complete(tVar);
            }
        }

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

        @Override // or.c
        public Type b() {
            return this.f31654a;
        }

        @Override // or.c
        /* renamed from: c, reason: merged with bridge method [inline-methods] */
        public CompletableFuture a(or.b bVar) {
            b bVar2 = new b(bVar);
            bVar.s0(new a(bVar2));
            return bVar2;
        }
    }

    e() {
    }

    @Override // or.c.a
    public or.c a(Type type, Annotation[] annotationArr, u uVar) {
        if (c.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 b10 = c.a.b(0, (ParameterizedType) type);
        if (c.a.c(b10) != t.class) {
            return new a(b10);
        }
        if (b10 instanceof ParameterizedType) {
            return new c(c.a.b(0, (ParameterizedType) b10));
        }
        throw new IllegalStateException("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
}
