using FastEndpoints;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.FastEndPoint;
using CRMSalesBLL.LeadAllocation;
using static GB5Shared.GB5Constant.Constant;
namespace CRMSalesSL.EndPoints.LeadAllocation;
/// Smart Lead Allocation v1 (capacity-based) — returns a SUGGESTION only, never an
/// auto-assignment. Confirming it is a normal Deal save (SaveDeal with RepId set).
public class SuggestAllocation : BaseEndpoint>
{
private readonly ILeadAllocationBLL _LeadAllocationBLL;
public SuggestAllocation(ILeadAllocationBLL leadAllocationBLL) => _LeadAllocationBLL = leadAllocationBLL;
public override void Configure()
{
Post("/LeadAllocation/SuggestAllocation");
AllowAnonymous();
}
public record SuggestAllocationParameters(
[property: FromHeader] string Login,
[property: QueryParam] int LeadId
);
protected override string? GetCacheKey(SuggestAllocationParameters req, LoginDTO login) => null;
protected override async Task> ExecuteAsync(SuggestAllocationParameters req, LoginDTO login, CancellationToken ct)
{
try
{
var result = await _LeadAllocationBLL.SuggestAllocationAsync(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);
}
}
}