package infrastructure.healthcheck;

import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;

@Liveness
@ApplicationScoped
@Slf4j
public class ApplicationLivenessCheck implements HealthCheck {

    private final String applicationName;
    private final String applicationVersion;


    public ApplicationLivenessCheck(
            @ConfigProperty(name = "quarkus.application.name", defaultValue = "api-application") String applicationName,
            @ConfigProperty(name = "quarkus.application.version", defaultValue = "unknown") String applicationVersion) {
        this.applicationName = applicationName;
        this.applicationVersion = applicationVersion;
    }

    @Override
    public HealthCheckResponse call() {
        log.debug("Ejecutando liveness health check: {}", System.currentTimeMillis());
        return HealthCheckResponse.named("API")
                .up()
                .withData("application", applicationName)
                .withData("version", applicationVersion)
                .withData("timestamp", System.currentTimeMillis())
                .build();
    }
}