using FastEndpoints;
using GB5Shared.ValidationCriteria;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.FastEndPoint;
using Newtonsoft.Json;
using static GB5Shared.GB5Constant.Constant;
namespace FrameworkSL.Endpoints.Validation
{
/// Exposes IValidationCriteriaEvaluator over HTTP for callers that can't take an
/// in-process reference to GB5Shared (cross-host case — see the roadmap doc's
/// "EIP <-> EAI hosting boundary" note; the same in-process-vs-HTTP consideration applies here).
/// In-process callers (e.g. WI) should call IValidationCriteriaEvaluator directly instead of
/// round-tripping through this endpoint.
public class GetUnmetValidationCriteria : BaseEndpoint>
{
private readonly IValidationCriteriaEvaluator _Evaluator;
public GetUnmetValidationCriteria(IValidationCriteriaEvaluator evaluator)
{
_Evaluator = evaluator;
}
public override void Configure()
{
Get("/Validation/GetUnmetValidationCriteria");
AllowAnonymous();
}
public record GetUnmetValidationCriteriaParameters(
[property: QueryParam] short EntityType,
[property: QueryParam] int EntityId,
[property: QueryParam] int EntityStepId,
[property: QueryParam] int EmployeeId,
[property: FromHeader] string Login
);
// Employee proof (skill level, quiz/assessment pass status) changes whenever an attempt runs —
// a display-before-commit eligibility check must always read live, never from cache.
protected override string? GetCacheKey(GetUnmetValidationCriteriaParameters req, LoginDTO loginDTO) => null;
protected override async Task> ExecuteAsync(GetUnmetValidationCriteriaParameters req, LoginDTO loginDTO, CancellationToken ct)
{
try
{
var result = await _Evaluator.GetUnmetValidationCriteriaAsync(req.EntityType, req.EntityId, req.EntityStepId, req.EmployeeId, loginDTO, ct);
return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(JsonConvert.SerializeObject(result), CacheKeyLevel.NOT_REQUIRED, loginDTO);
}
catch (Exception ex)
{
return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500);
}
}
}
}