package org.kar.karideo.api;

import org.kar.archidata.exception.FailException;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.archidata.tools.JWTWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.security.PermitAll;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

@Path("/health_check")
@Produces(MediaType.APPLICATION_JSON)
public class HealthCheck {
	static final Logger LOGGER = LoggerFactory.getLogger(HealthCheck.class);

	public record HealthResult(String value) {

	};

	@GET
	@PermitAll
	@Operation(description = "Get the server state (health)", tags = "SYSTEM")
	public HealthResult getHealth() throws FailException {
		if (JWTWrapper.getPublicKeyJson() == null && !ConfigBaseVariable.getTestMode()) {
			throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Missing Jwt public token");
		}
		return new HealthResult("alive and kicking");
	}
}
