using System.Data; using GB5Shared.DTO.Ice; using GB5Shared.DTO.Framework.Login; using IceImportDAL.DTO.IceImportPipeline; namespace IceImportBLL.FieldResolvers; // One resolved value + optional warning finding (never a silent default — see SourceValueResolver). public class FieldResolutionResult { public object? Value { get; set; } public IceImportFieldErrorDTO? Warning { get; set; } public static FieldResolutionResult Ok(object? value) => new() { Value = value }; public static FieldResolutionResult WithWarning(object? value, IceImportFieldErrorDTO warning) => new() { Value = value, Warning = warning }; } // Everything a single-field resolver needs: the IceMapDetails config row driving this field, the // current source DataRow, the caller's LoginDTO, the pre-resolved Code/Name -> Id lookup tables // (populated once up front by IEntityLookupService — no per-row I/O), and hierarchy context for // parent/grandparent id resolvers. public class FieldResolutionContext { public required IceMapDetailsDTO DetailConfig { get; init; } public required DataRow SourceRow { get; init; } public required LoginDTO Login { get; init; } public required int RowNumber { get; init; } // Keyed by IceMapDetails.EntityId (the entity being looked up), then by the raw code/name // value from the source file -> resolved target Id. public IReadOnlyDictionary> Lookups { get; init; } = new Dictionary>(); // ValueType=6 (ParentIdAssignmentResolver): the immediate parent row's correlation/real id. public int? ParentId { get; init; } // ValueType=8 (FirstParentValueResolver): the grandparent row's id, for 3-level hierarchies. public int? FirstParentId { get; init; } // Threaded through so ValueType=9/10 (Fixed/Global "during update") resolvers know whether // this row is being inserted or updated. public bool IsUpdateMode { get; init; } } // One implementation per legacy IceMapDetailsValueType. DI-scanned as // IEnumerable; the pipeline selects by ValueType, modeled on // GB5Shared.GB5Library.Qualifier.IQualifierExecutor's Key-based dispatch style. public interface IIceFieldValueResolver { int ValueType { get; } Task ResolveAsync(FieldResolutionContext ctx, CancellationToken ct); }