package eu.teraflow.automation;

import grpc.health.v1.HealthGrpc;
import grpc.health.v1.HealthOuterClass;
import io.quarkus.grpc.GrpcClient;
import io.smallrye.mutiny.Uni;
import org.jboss.logging.Logger;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class ContextHealthCheckImpl implements ContextHealthCheck {

    private static final Logger LOGGER = Logger.getLogger(ContextHealthCheckImpl.class);

    @GrpcClient("health")
    HealthGrpc.HealthBlockingStub healthDelegate;

    @Override
    public Uni<HealthOuterClass.HealthCheckResponse> getServingStatus() {
        final var request = HealthOuterClass.HealthCheckRequest.newBuilder().build();

        final var contextHealthCheckResponse = healthDelegate.check(request);
        LOGGER.infof("Context service health response: %s", contextHealthCheckResponse);

        return Uni.createFrom().item(contextHealthCheckResponse);
    }
}
