using GB5Shared.DTO.Framework.Login; using GB5Shared.EntityHandler; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using PIEDAL.CustomCode.Outcome; using PIEDAL.DTO.Outcome; using static GB5Shared.GB5Constant.Constant; namespace PIEBLL.Outcome; public class PIEOutcomeBLL : IPIEOutcomeBLL { private readonly IPIEOutcomeDAL _PIEOutcomeDAL; private readonly IQueryExecutor _QueryExecutor; private readonly BaseEntityAppService _BaseEntityAppService; public PIEOutcomeBLL( IPIEOutcomeDAL pieOutcomeDAL, IQueryExecutor queryExecutor, BaseEntityAppService baseEntityAppService) { _PIEOutcomeDAL = pieOutcomeDAL; _QueryExecutor = queryExecutor; _BaseEntityAppService = baseEntityAppService; } // ── Read ────────────────────────────────────────────────────────────────── public async Task GetPIEOutcomeAsync( Guid outcomeId, LoginDTO login, CancellationToken ct) => await _PIEOutcomeDAL.GetPIEOutcomeAsync(outcomeId, login, ct).ConfigureAwait(false); // ── Write (insert-only — outcomes are the immutable historical record) ──── public async Task RecordPIEOutcomeAsync( PIEOutcomeDTO dto, LoginDTO login, CancellationToken ct) { if (dto is null) throw new ArgumentNullException(nameof(dto)); if (dto.OutcomeId == Guid.Empty) dto.OutcomeId = Guid.NewGuid(); var Trans = await _QueryExecutor.BeginTransactionAsync(login).ConfigureAwait(false); try { await _BaseEntityAppService.ExecuteSaveAsync( EntityConstant.OBJECTPIEOUTCOME, EventTypeConstant.SAVEPIEMODULEEVENTTYPEID, // outcome recorded event dto, login, async tx => { await _PIEOutcomeDAL.InsertPIEOutcomeAsync(dto, login, tx, ct); return 0; // PIEOutcome uses a Guid PK — no int object ID to report back }, null, -1, -1, Trans).ConfigureAwait(false); await _QueryExecutor.CommitAsync(Trans).ConfigureAwait(false); return SuccessResponse.SaveSuccess; } catch (Exception ex) { GB5Shared.Telemetry.GB5Trace.MarkFailed("record-pie-outcome-failed", ex); await _QueryExecutor.RollbackAsync(Trans).ConfigureAwait(false); throw; } } }