using AutomationDAL.CustomCode.ScriptParam; using AutomationDAL.DTO.ScriptParam; using GB5Shared.DTO.Framework.Login; using GB5Shared.Resource.Response; using Microsoft.Extensions.Logging; namespace AutomationBLL.ScriptParam; public class ScriptParamBLL : IScriptParamBLL { private readonly IScriptParamDAL _dal; private readonly ILogger _logger; public ScriptParamBLL(IScriptParamDAL dal, ILogger logger) { _dal = dal; _logger = logger; } public async Task> GetByScript(int scriptId, LoginDTO login, CancellationToken ct) => await _dal.GetByScript(scriptId, login, ct).ConfigureAwait(false); public async Task Save(ScriptParamDTO dto, LoginDTO login, CancellationToken ct) { try { if (dto.ScriptId <= 0) throw new InvalidOperationException("ScriptId is required."); if (string.IsNullOrWhiteSpace(dto.ParamName)) throw new InvalidOperationException("ParamName is required."); if (string.IsNullOrWhiteSpace(dto.ParamType)) throw new InvalidOperationException("ParamType is required."); int newId = await _dal.Insert(dto, login, ct).ConfigureAwait(false); return $"{SuccessResponse.SaveSuccessMessage} {newId}"; } catch (Exception ex) { _logger.LogError(ex, "Save failed for ScriptParam {ParamName}", dto.ParamName); throw; } } public async Task Delete(int paramId, LoginDTO login, CancellationToken ct) { await _dal.Delete(paramId, login, ct).ConfigureAwait(false); return SuccessResponse.DeleteSuccessMessage; } }