using Aitex.Core.RT.Routine;
using CyberX8_Core;
using MECF.Framework.Common.Persistent.Prewet;
using MECF.Framework.Common.Routine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CyberX8_RT.Devices.Prewet
{
    public class PrewetPumpDisableRoutine : RoutineBase, IRoutine
    {
        private enum PumpDisableStep
        {
            PumpDisable,
            Delay,
            PumpValveClose,
            End
        }

        #region 内部变量
        PrewetDevice _device;
        PrewetPersistentValue _prewetPersistentValue;
        #endregion

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="module"></param>
        public PrewetPumpDisableRoutine(string module, PrewetDevice prewetDevice, PrewetPersistentValue prewetPersistentValue) : base(module)
        {
            _device = prewetDevice;
            _prewetPersistentValue = prewetPersistentValue;
        }
        /// <summary>
        /// 中止
        /// </summary>
        public void Abort()
        {
            Runner.Stop("Manual Abort");
        }
        /// <summary>
        /// 监控
        /// </summary>
        /// <returns></returns>
        public RState Monitor()
        {
            Runner.Run(PumpDisableStep.PumpDisable, _device.PumpDisable, 500)
                .Delay(PumpDisableStep.Delay, 500)
                .Run(PumpDisableStep.PumpValveClose, _device.PumpValveClose, 500)
                .End(PumpDisableStep.End, NullFun, _delay_1ms);
            return Runner.Status;
        }
        /// <summary>
        /// 启动
        /// </summary>
        /// <param name="objs"></param>
        /// <returns></returns>
        public RState Start(params object[] objs)
        {
            return Runner.Start(Module, "Pump Disable");
        }

    }
}