using FastEndpoints;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.DTO.Report;
using GB5Shared.FastEndPoint;
using PayRollBLL.PayProcess;
using PayRollDAL.DTO.PayProcess;
using static GB5Shared.GB5Constant.Constant;
namespace PayRollSL.EndPoints.PayProcess;
///
/// Salary Abstract Summary follows the same report endpoint/BLL/DAL pattern as
/// AccountsSL's GetDayBooks endpoint, including streaming export support.
///
public sealed class SalaryAbstractSummary : BaseReportEndpoint
{
private readonly ISalaryAbstractSummaryBLL _bll;
public SalaryAbstractSummary(ISalaryAbstractSummaryBLL bll)
{
_bll = bll;
}
public override void Configure()
{
Post("/PayProcess/SalaryAbstractSummary");
AllowAnonymous();
}
public record Request(
[property: FromHeader] string Login,
[property: FromBody] ReportCallingDTO ReportCallingDTO,
[property: QueryParam] int FirstNumber,
[property: QueryParam] int MaxResult);
public override async Task HandleAsync(Request req, CancellationToken ct)
{
// GB4 callers commonly carry a ReportFormat header while sending a legacy
// negative ReportViewId. That header switches BaseReportEndpoint into the
// metadata/export pipeline, which cannot resolve a report view and can
// fail before the Salary Abstract query is executed. Treat it as the
// normal paged report request; real exports require a valid positive view.
if (req.ReportCallingDTO?.ReportViewId <= 0)
HttpContext.Request.Headers.Remove("ReportFormat");
await base.HandleAsync(req, ct);
}
protected override IAsyncEnumerable ExecuteReportAsync(
Request req, LoginDTO login, CancellationToken ct) =>
_bll.GetSalaryAbstractSummaryStream(
req.FirstNumber, req.MaxResult, req.ReportCallingDTO.CriteriaDTO, login, ct);
protected override async Task> ExecutePagedAsync(
Request req, LoginDTO login, CancellationToken ct)
{
var result = await _bll.GetSalaryAbstractSummary(
req.FirstNumber, req.MaxResult, req.ReportCallingDTO.CriteriaDTO, login, ct);
return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(
result, CacheKeyLevel.NOT_REQUIRED, login);
}
}