package org.kar.karusic.api;

import org.kar.archidata.exception.FailException;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.archidata.tools.JWTWrapper;

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 {

	public record HealthResult(String value) {
	};

	@GET
	@PermitAll
	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");
	}
}
