using System;
using Aitex.Core.RT.Log;
using Aitex.Core.RT.Routine;
using Aitex.Core.RT.SCCore;
using MECF.Framework.Common.Equipment;

namespace SicModules.LLs.Routines
{
    public class LoadHomeRoutine : LoadLockBaseRoutine
    {
        enum RoutineStep
        {
            CloseV79,
            CloseV83,
            CloseV84, 
            CloseV85
        }

        private int _homeTimeout;

        public LoadHomeRoutine(ModuleName module)
        {
            Module = module.ToString();
            Name = "Home";
        }

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

            _homeTimeout = SC.GetValue<int>("LoadLock.HomeTimeout");

            Notify("Start");

            return Result.RUN;
        }

        public override Result Monitor()
        {
            try
            {
                CloseLoadVent((int)RoutineStep.CloseV79);
                CloseFastPump((int)RoutineStep.CloseV83);
                CloseSlowPump((int)RoutineStep.CloseV84);
                CloseBalanceValve((int)RoutineStep.CloseV85);

                LoadLockDevice.AutoCreatWafer();
            }
            catch (RoutineBreakException)
            {
                return Result.RUN;
            }
            catch (RoutineFaildException ex)
            {
                LOG.Error(ex.ToString());
                return Result.FAIL;
            }

            Notify("Finished");

            return Result.DONE;
        }

        public override void Abort()
        {
            base.Abort();
        }

    }
}
