using BizProcessBLL.Interfaces; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace BizProcessSL.Endpoints.Reports { // Phase 9a -- "Process Traceability Report" PDF, same rendering pipeline/rationale as // GetProcessControlCopy.cs. Renders Phase 7's instance-trace result (visited/current/future // stages) as a formatted document -- no new data-gathering, a document view of data // GetProcessInstanceTrace already computes. public class GetProcessTraceabilityReport : BaseEndpoint> { private readonly IBizProcessBLL _bll; public GetProcessTraceabilityReport(IBizProcessBLL bll) => _bll = bll; public override void Configure() { Get("/BizProcess/Reports/GetProcessTraceabilityReport"); AllowAnonymous(); } public record Parameters( [property: FromHeader] string Login, [property: QueryParam] int BizProcessVariantId, [property: QueryParam] int PivotAllocationId ); protected override string? GetCacheKey(Parameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync(Parameters req, LoginDTO login, CancellationToken ct) { try { var pdfBytes = await _bll.GetProcessTraceabilityReportPdf(req.BizProcessVariantId, req.PivotAllocationId, login, ct).ConfigureAwait(false); using var ms = new MemoryStream(pdfBytes); await HttpContext.Response.SendStreamAsync(ms, $"ProcessTraceabilityReport_{req.PivotAllocationId}.pdf", ms.Length, "application/pdf", cancellation: ct); return null!; } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } } }