using Aitex.Core.RT.Log;
using Aitex.Core.RT.RecipeCenter;
using Aitex.Core.UI.MVVM;
using MECF.Framework.Common.CommonData;
using MECF.Framework.Common.CommonData.Dryer;
using MECF.Framework.Common.DataCenter;
using MECF.Framework.Common.Device.Rinse;
using MECF.Framework.Common.OperationCenter;
using MECF.Framework.Common.Persistent.Dryer;
using MECF.Framework.Common.Persistent.Rinse;
using MECF.Framework.Common.RecipeCenter;
using MECF.Framework.Common.Utilities;
using MECF.Framework.Common.WaferHolder;
using CyberX8_Core;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
namespace CyberX8_MainPages.ViewModels
{
    internal class DryerHomePageViewModel:BindableBase
    {
        #region 常量
        private const string COMMON_DATA = "CommonData";
        private const string DRYER = "dryer";
        private const string PERSISTENT_VALUE = "PersistentValue";
        private const string EXHAUST_LIMIT_DATA = "ExhaustLimitData";
        #endregion
        #region 内部变量
        #region Common
        /// 
        /// 模块名称
        /// 
        private string _module;
        /// 
        /// 数据
        /// 
        private DryerCommonData _dryerCommonData;
        /// 
        /// 当前选择Recipe节点
        /// 
        private RecipeNode _selectedRecipeNode;
        /// 
        /// Persistent
        /// 
        private DryerPersistentValue _dryerPersistent;
        #endregion
        #region Wafer Holder
        /// 
        /// Wafer Holder属性
        /// 
        private WaferHolderInfo _waferHolderInfo;
        /// 
        /// SeqRecipe
        /// 
        private string _seqRecipe;
        /// 
        /// Interlocks
        /// 
        private bool _interlocks;
        /// 
        /// ExhaustData
        /// 
        private CommonLimitData _exhaustData;
        #endregion
        #region 系统数据
        /// 
        /// 定时器
        /// 
        DispatcherTimer _timer;
        /// 
        /// 查询后台数据集合
        /// 
        private List _rtDataKeys = new List();
        /// 
        /// rt查询key数值字典
        /// 
        private Dictionary _rtDataValueDic = new Dictionary();
        #endregion
        #region Dryer1
        /// 
        /// RecipeContent
        /// 
        private string _recipeContent;
        /// 
        /// TimeRemaining 
        /// 
        private int _timeRemaining;
        /// 
        /// OfTotalTime 
        /// 
        private int _totalTime;
        /// 
        /// OperatingMode 
        /// 
        private string _operatingMode;
        /// 
        /// State
        /// 
        private string _state;
        /// 
        /// RecipeMode 
        /// 
        private string _recipeMode;
        #endregion
        #region HVD recipe
        /// 
        /// RecipeModuleName
        /// 
        private string _recipeModuleName;
        /// 
        /// RecipeType
        /// 
        private string _recipeType;
        /// 
        /// AchievedRunRecipeCycle
        /// 
        private int _achievedRunRecipeCycle;
        /// 
        /// 当前Recipe
        /// 
        private string _currentRecipe;
        #endregion
        #region UI Related
        /// 
        /// InterLock
        /// 
        private bool _interLock;
        /// 
        /// IsErrorState 用于腔体变红
        /// 
        private bool _isErrorState;
        /// 
        /// 用于Exhaust warning时灯变黄
        /// 
        private int _isExhaustWarning = 0;
        /// 
        /// 倒计时
        /// 
        private int _countDownSecond = 0;
        /// 
        /// 页面功能启用
        /// 
        private bool _isEnabled;
        /// 
        /// AutoMode页面功能启用
        /// 
        private bool _isAutoEnabled;
        /// 
        /// 是否存在WaferHolder
        /// 
        private bool _isWaferHolder;
        #endregion
        #endregion
        #region 属性
        #region Common
        /// 
        /// 模块名称
        /// 
        public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
        /// 
        /// Interlocks
        /// 
        public bool InterLocks { get { return _interlocks; } set { SetProperty(ref _interlocks, value); } }
        /// 
        /// ExhaustData
        /// 
        public CommonLimitData ExhaustData
        {
            get { return _exhaustData; }
            set { SetProperty(ref _exhaustData, value); }
        }
        /// 
        /// Commondata
        /// 
        public DryerCommonData DryerCommonData
        {
            get { return _dryerCommonData; }
            set { SetProperty(ref _dryerCommonData, value); }
        }
        /// 
        /// Threshold
        /// 
        public DryerPersistentValue DryerPersistent
        {
            get { return _dryerPersistent; }
            set { SetProperty(ref _dryerPersistent, value); }
        }
        public RecipeNode SelectedRecipeNode
        {
            get { return _selectedRecipeNode; }
            set { SetProperty(ref _selectedRecipeNode, value); }
        }
        #endregion
        #region Dryer1
        /// 
        /// RecipeContent
        /// 
        public string RecipeContent
        {
            get { return _recipeContent; }
            set { SetProperty(ref _recipeContent, value); }
        }
        /// 
        /// TimeRemaining 
        /// 
        public int TimeRemaining
        {
            get { return _timeRemaining; }
            set { SetProperty(ref _timeRemaining, value); }
        }
        /// 
        /// TotalTime  
        /// 
        public int TotalTime
        {
            get { return _totalTime; }
            set { SetProperty(ref _totalTime, value); }
        }
        /// 
        /// OperatingMode
        /// 
        public string OperatingMode
        {
            get { return _operatingMode; }
            set { SetProperty(ref _operatingMode, value); }
        }
        /// 
        /// State
        /// 
        public string State
        {
            get { return _state; }
            set { SetProperty(ref _state, value); }
        }
        /// 
        /// RecipeMode
        /// 
        public string RecipeMode
        {
            get { return _recipeMode; }
            set { SetProperty(ref _recipeMode, value); }
        }
        #endregion
        #region HVD recipe
        /// 
        /// RecipeModuleName
        /// 
        public string RecipeModuleName
        {
            get { return _recipeModuleName; }
            set { SetProperty(ref _recipeModuleName, value); }
        }
        /// 
        /// RecipeType
        /// 
        public string RecipeType
        {
            get { return _recipeType; }
            set { SetProperty(ref _recipeType, value); }
        }
        /// 
        /// Run Recipe已经完成的次数
        /// 
        public int AchievedRunRecipeCycle
        {
            get { return _achievedRunRecipeCycle; }
            set { SetProperty(ref _achievedRunRecipeCycle, value); }
        }
        /// 
        /// 当前Recipe
        /// 
        public string CurrentRecipe
        {
            get { return _currentRecipe; }
            set { SetProperty(ref _currentRecipe, value); }
        }
        #endregion
        #region Wafer Holder
        /// 
        /// Wafer Holder属性
        /// 
        public WaferHolderInfo WaferHolderInfo { get { return _waferHolderInfo; } set { SetProperty(ref _waferHolderInfo, value); } }
        /// 
        /// SeqRecipe
        /// 
        public string SeqRecipe
        {
            get { return _seqRecipe; }
            set { SetProperty(ref _seqRecipe, value); }
        }
        #endregion
        #region UI Related
        /// 
        /// IsErrorState
        /// 
        public bool IsErrorState { get { return _isErrorState; } set { SetProperty(ref _isErrorState, value); } }
        /// 
        /// ClampStatus
        /// 
        public bool InterLock
        {
            get { return _interLock; }
            set { SetProperty(ref _interLock, value); }
        }
        /// 
        /// IsErrorState
        /// 
        public int IsExhaustWarning { get { return _isExhaustWarning; } set { SetProperty(ref _isExhaustWarning, value); } }
        /// 
        /// 倒计时
        /// 
        public int CountDownSecond { get { return _countDownSecond; } set { SetProperty(ref _countDownSecond , value); } }
        /// 
        /// 页面功能启用
        /// 
        public bool IsEnabled
        {
            get { return _isEnabled; }
            set { SetProperty(ref _isEnabled, value); }
        }
        /// 
        /// AutoMode页面功能启用
        /// 
        public bool IsAutoEnabled
        {
            get { return _isAutoEnabled; }
            set { SetProperty(ref _isAutoEnabled, value); }
        }
        /// 
        /// 是否存在WaferHolder
        /// 
        public bool IsWaferHolder { get { return _isWaferHolder; } set { SetProperty(ref _isWaferHolder, value); } }
        #endregion
        #endregion
        #region Command指令
        public ICommand InitializeCommand { get; set; }
        public ICommand PowerOnCommand { get; set; }
        public ICommand PowerOffCommand { get; set; }
        public ICommand BlowerHighCommand { get; set; }
        public ICommand BlowerLowCommand { get; set; }
        public ICommand BypassCommand { get; set; }
     
        #endregion
        /// 
        /// 构造函数
        /// 
        public DryerHomePageViewModel()
        {
            InitializeCommand = new DelegateCommand