using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using QMSBLL.PcsCardMaterial; using QMSBLL.PcsCardStage; using QMSDAL.DTO; using static GB5Shared.GB5Constant.Constant; namespace QMSSL.EndPoints.PcsCardStage; // Saves stage quantity fields + materials in one call. // Stage lifecycle transitions (Open/Complete/Skip/Ncr) use their dedicated endpoints. public class SavePcsCardStage : BaseEndpoint> { private readonly IPcsCardMaterialBLL _materialBll; public SavePcsCardStage(IPcsCardMaterialBLL materialBll) => _materialBll = materialBll; public override void Configure() { Post("/PcsCardStage/SavePcsCardStage"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: FromBody] PcsStageSaveDTO Body); protected override string? GetCacheKey(Params req, LoginDTO login) => null; protected override async Task> ExecuteAsync( Params req, LoginDTO login, CancellationToken ct) { try { // Persist material batch entries for the stage var materialsDto = new PcsStageMaterialsDTO { PcsCardStaeId = req.Body.Stage.PcsCardStaeId, Materials = req.Body.Materials }; var result = await _materialBll.SaveAllAsync(materialsDto, 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); } } }