using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; using StructureHelperLogics.Models.CrossSections; namespace DataAccess.DTOs { public class CrossSectionToDTOConvertStrategy : IConvertStrategy { private IUpdateStrategy updateStrategy; //don't use since CrossSection does not have any properties private IConvertStrategy convertRepositoryStrategy; private DictionaryConvertStrategy convertLogic; private ICheckConvertLogic checkLogic; public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public IShiftTraceLogger TraceLogger { get; set; } public CrossSectionToDTOConvertStrategy(IUpdateStrategy updateStrategy, IConvertStrategy convertRepositoryStrategy, ICheckConvertLogic checkLogic) { this.updateStrategy = updateStrategy; this.convertRepositoryStrategy = convertRepositoryStrategy; this.checkLogic = checkLogic; } public CrossSectionToDTOConvertStrategy() : this( new CrossSectionUpdateStrategy(), new CrossSectionRepositoryToDTOConvertStrategy(), new CheckConvertLogic()) { } public CrossSectionDTO Convert(ICrossSection source) { Check(); CrossSectionDTO newItem = new() { Id = source.Id }; convertRepositoryStrategy.ReferenceDictionary = ReferenceDictionary; convertRepositoryStrategy.TraceLogger = TraceLogger; convertLogic = new DictionaryConvertStrategy(this, convertRepositoryStrategy); newItem.SectionRepository = convertLogic.Convert(source.SectionRepository); return newItem; } private void Check() { checkLogic.ConvertStrategy = this; checkLogic.TraceLogger = TraceLogger; checkLogic.Check(); } } }