using FrameworkDAL.Query.EIPConversation.EIPStepExecutionLog; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.QueryExecutor; using Microsoft.Extensions.Logging; using System; using System.Threading; using System.Threading.Tasks; using static GB5Shared.GB5Constant.Constant; namespace FrameworkDAL.CustomCode.EIPConversation.EIPStepExecutionLog { public class EIPStepExecutionLogDAL : IEIPStepExecutionLogDAL { private readonly IQueryExecutor _qe; private readonly AutoNumber _autoNumber; private readonly ILogger _logger; public EIPStepExecutionLogDAL(IQueryExecutor qe, AutoNumber autoNumber, ILogger logger) { _qe = qe ?? throw new ArgumentNullException(nameof(qe)); _autoNumber = autoNumber ?? throw new ArgumentNullException(nameof(autoNumber)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } public async Task InsertAsync( int interactionSessionId, string stepCode, byte stepType, byte stepStatus, long durationMs, string? inputValue, string? decisionCode, string? errorMessage, LoginDTO loginDTO, CancellationToken ct = default) { try { var auto = await _autoNumber.GetNumberAsync(1, AUTONUMBERCONSTANT.EIPSTEPEXECUTION, loginDTO) .ConfigureAwait(false); await _qe.ExecuteAsync( loginDTO, EIPStepExecutionLogQB.INSERT, new { StepExecutionId = auto.StartNumber, InteractionSessionId = interactionSessionId, StepCode = stepCode, StepType = stepType, StepStatus = stepStatus, DurationMs = durationMs, InputValue = inputValue, DecisionCode = decisionCode, ErrorMessage = errorMessage }, cancellationToken: ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "Failed to insert step execution log | InteractionSessionId={Id} | Step={Step}", interactionSessionId, stepCode); throw; } } } }