using FastEndpoints;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.FastEndPoint;
using CRMSalesBLL.LeadScoring;
using static GB5Shared.GB5Constant.Constant;
namespace CRMSalesSL.EndPoints.LeadScoring;
/// Triggers LeadScoringBLL.RecalculateLeadScoreAsync for one Lead — not itself part of
/// this pass's brief as an explicit endpoint requirement, but added so the BLL method is reachable
/// over HTTP (mirrors this repo's action-endpoint shape, e.g. Communication/SendCommunication).
public class RecalculateLeadScore : BaseEndpoint>
{
private readonly ILeadScoringBLL _LeadScoringBLL;
public RecalculateLeadScore(ILeadScoringBLL leadScoringBLL) => _LeadScoringBLL = leadScoringBLL;
public override void Configure()
{
Post("/LeadScoring/RecalculateLeadScore");
AllowAnonymous();
}
public record RecalculateLeadScoreParameters(
[property: FromHeader] string Login,
[property: QueryParam] int LeadId
);
protected override string? GetCacheKey(RecalculateLeadScoreParameters req, LoginDTO login) => null;
protected override async Task> ExecuteAsync(RecalculateLeadScoreParameters req, LoginDTO login, CancellationToken ct)
{
try
{
var result = await _LeadScoringBLL.RecalculateLeadScoreAsync(req.LeadId, login!, ct);
return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, login);
}
catch (Exception ex)
{
return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500);
}
}
}