package com.banesco.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());

        // Simplemente reportamos que la aplicación está activa
        // Si este código se ejecuta, significa que la JVM está funcionando
        return HealthCheckResponse.named("API")
                .up()
                .withData("application", applicationName)
                .withData("version", applicationVersion)
                .withData("timestamp", System.currentTimeMillis())
                .build();
    }
}