using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;

namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.Logics
{
    public class ForceCalculatorUpdateStrategy : IUpdateStrategy<IForceCalculator>
    {
        private readonly IUpdateStrategy<IForceCalculatorInputData> inputDataUpdateStrategy;
        public ForceCalculatorUpdateStrategy(IUpdateStrategy<IForceCalculatorInputData> inputDataUpdateStrategy)
        {
            this.inputDataUpdateStrategy = inputDataUpdateStrategy;
        }
        public ForceCalculatorUpdateStrategy() : this(new ForceCalculatorInputDataUpdateStrategy()) {        }
        public void Update(IForceCalculator targetObject, IForceCalculator sourceObject)
        {
            CheckObject.ThrowIfNull(targetObject);
            CheckObject.ThrowIfNull(sourceObject);
            if (ReferenceEquals(targetObject, sourceObject)) { return; }
            targetObject.Name = sourceObject.Name;
            targetObject.ShowTraceData = sourceObject.ShowTraceData;
            targetObject.InputData ??= new ForceCalculatorInputData();
            inputDataUpdateStrategy.Update(targetObject.InputData, sourceObject.InputData);
        }
    }
}
