using System.Threading; using System.Threading.Tasks; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.GOP; using Microsoft.Extensions.Logging; namespace FrameworkBLL.GOP.Worker.NodeExecutors { // ============================================================ // MapperNodeExecutor — executes a Mapper node type. // // Delegates to IMappingEngineBLL to transform the input payload // using the mapping definition referenced by the step's // LogicalServiceName (treated as the MapperCode). // // Returns the transformed payload JSON. // Phase 4 upgrades MappingEngineBLL to support [FactBag] paths. // ============================================================ public class MapperNodeExecutor : INodeExecutor { private readonly IMappingEngineBLL _MappingEngine; private readonly ILogger _Logger; public MapperNodeExecutor( IMappingEngineBLL mappingEngine, ILogger logger) { _MappingEngine = mappingEngine; _Logger = logger; } public string NodeType => "Mapper"; public async Task ExecuteAsync( GopFlowSnapshotStepDTO step, GopExecutionHeaderDTO header, string? inputPayloadJson, LoginDTO loginDTO, CancellationToken ct) { _Logger.LogDebug( "MapperNodeExecutor: execution {ExecutionId} step {NodeCode}", header.ExecutionId, step.NodeCode); // IMappingEngineBLL.TransformAsync accepts the mapper code + source payload JSON. // Phase 4 will add [FactBag] path resolution to the engine. var result = await _MappingEngine.TransformAsync( step.LogicalServiceName, // MapperCode stored in LogicalServiceName inputPayloadJson ?? "{}", loginDTO, ct); _Logger.LogDebug( "MapperNodeExecutor: execution {ExecutionId} step {NodeCode} complete", header.ExecutionId, step.NodeCode); return result; } } }