using GB5Shared.DTO.Framework.Login; using GB5Shared.Telemetry; using JobEngineDAL.Interfaces; using JobEngineBLL.Interfaces; using Microsoft.Extensions.Logging; using Newtonsoft.Json; namespace JobEngineBLL.Implementations { public class JobExecutionBLL : IJobExecutionBLL { private readonly IJobExecutionDAL _dal; private readonly ILogger _logger; public JobExecutionBLL(IJobExecutionDAL dal, ILogger logger) { _dal = dal; _logger = logger; } public async Task GetHistoryAsync( int? jobId, string? status, int page, int pageSize, LoginDTO login, CancellationToken ct) { try { var (items, total) = await _dal.GetHistoryPagedAsync( login.ClientId, jobId, status, page, pageSize, login, ct).ConfigureAwait(false); return JsonConvert.SerializeObject(new { Items = items, TotalCount = total, Page = page, PageSize = pageSize }); } catch (Exception ex) { GB5Trace.MarkFailed("get-execution-history-failed", ex); _logger.LogError(ex, "GetHistory failed for tenant {TenantId}", login.ClientId); throw; } } public async Task GetExecutionDetailAsync(long executionId, LoginDTO login, CancellationToken ct) { try { var detail = await _dal.GetExecutionDetailAsync(executionId, login, ct).ConfigureAwait(false); return JsonConvert.SerializeObject(detail); } catch (Exception ex) { GB5Trace.MarkFailed("get-execution-detail-failed", ex); _logger.LogError(ex, "GetExecutionDetail failed for ExecutionId {Id}", executionId); throw; } } } }