using Aitex.Core.RT.Routine;
using MECF.Framework.Common.Equipment;
using SicModules.PMs.Routines.Base;

namespace SicModules.PMs.Routines
{
    public class PMStopHeatEnableRoutine : PMBaseRoutine
    {
        enum RoutineStep
        {
            SetPSUDisable,
            SetSCRDisable,
        }

        private int _heatTimeOut = 5;

        public PMStopHeatEnableRoutine(ModuleName module, PMModule pm1) : base(module, pm1)
        {
            Module = module.ToString();
            Name = "StopEnable";
        }

        public override Result Start(params object[] objs)
        {
            Reset();

            Notify("Start");
            return Result.RUN;
        }

        public override Result Monitor()
        {
            try
            {
                SetPSUEnable((int)RoutineStep.SetPSUDisable, false, _heatTimeOut);

                SetSCREnable((int)RoutineStep.SetSCRDisable, false, _heatTimeOut);

            }
            catch (RoutineBreakException)
            {
                return Result.RUN;
            }
            catch (RoutineFaildException)
            {
                return Result.FAIL;
            }

            Notify("Finished");

            return Result.DONE;
        }
    }
}
