using System.Diagnostics;
using Aitex.Core.RT.IOCore;
using Aitex.Core.Util;

namespace Aitex.Core.RT.Device.Devices
{ 
    internal class IoTCHeaterLoop
    {
        private readonly DeviceTimer _rampTimer;

        public IoTCHeaterLoop(int id, AOAccessor aoTargetSP, AOAccessor aoTempFromSensorToTC)
        {
            Debug.Assert(aoTargetSP != null);
            Debug.Assert(aoTempFromSensorToTC != null);

            Name = $"L{id}";
            _rampTimer = new DeviceTimer();
            AOTargetSP = aoTargetSP;
            AOTempFromSensorTC = aoTempFromSensorToTC;
        }

        public string Name { get; }

        /// <summary>
        /// TC Auto模式时控温目标温度。
        /// </summary>
        public AOAccessor AOTargetSP { get; private set; }

        /// <summary>
        /// 从温度传感器读到的实时温度通过此AO写入2704.
        /// </summary>
        public AOAccessor AOTempFromSensorTC { get; private set; }

        public DeviceTimer RampTimer => _rampTimer;

        public float RampInitTemp { get; set; }

        public float RampTargetTemp { get; set; }

        public int RampDurationMs { get; private set; }

        public void StartRamp(int duration)
        {
            RampDurationMs = duration;
            _rampTimer.Start(duration);
        }

        public void StopRamp()
        {
            RampDurationMs = 0;
            _rampTimer.Stop();
        }
    }
}
