using AutomationDAL.CustomCode.EventMap; using AutomationDAL.DTO.EventMap; using GB5Shared.DTO.Framework.Login; using GB5Shared.Resource.Response; using Microsoft.Extensions.Logging; namespace AutomationBLL.EventMap; public class EventMapBLL : IEventMapBLL { private readonly IEventMapDAL _dal; private readonly ILogger _logger; public EventMapBLL(IEventMapDAL dal, ILogger logger) { _dal = dal; _logger = logger; } public async Task Resolve(string eventType, int? customerId, LoginDTO login, CancellationToken ct) => await _dal.Resolve(eventType, customerId, login, ct).ConfigureAwait(false); public async Task> GetByTenant(LoginDTO login, CancellationToken ct) => await _dal.GetByTenant(login, ct).ConfigureAwait(false); public async Task Save(EventMapDTO dto, LoginDTO login, CancellationToken ct) { try { if (string.IsNullOrWhiteSpace(dto.EventType)) throw new InvalidOperationException("EventType is required."); if (string.IsNullOrWhiteSpace(dto.Stage)) throw new InvalidOperationException("Stage is required."); if (dto.TargetId <= 0) throw new InvalidOperationException("TargetId is required."); if (dto.MapId == 0) { int newId = await _dal.Insert(dto, login, ct).ConfigureAwait(false); return $"{SuccessResponse.SaveSuccessMessage} {newId}"; } await _dal.Update(dto, login, ct).ConfigureAwait(false); return SuccessResponse.UpdateSuccess; } catch (Exception ex) { _logger.LogError(ex, "Save failed for EventType {EventType}", dto.EventType); throw; } } }