using Aitex.Core.UI.MVVM;
using Aitex.Core.Utilities;
using MECF.Framework.Common.OperationCenter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace PunkHPX8_Themes.UserControls
{
    /// 
    /// VPWMainVacuumPumpControl.xaml 的交互逻辑
    ///  
    public partial class VPWMainVacuumPumpControl : UserControl
    {
        public VPWMainVacuumPumpControl()
        {
            KeyDownCommand = new DelegateCommand(KeyDownAction);
            InitializeComponent();
            
        }
        #region 属性
        public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
           "ModuleName", typeof(string), typeof(VPWMainVacuumPumpControl),
           new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// 模块名称
        ///  
        public string ModuleName
        {
            get
            {
                return (string)this.GetValue(ModuleNameProperty);
            }
            set
            {
                this.SetValue(ModuleNameProperty, value);
            }
        }
        public static readonly DependencyProperty InputPumpSpeedProperty = DependencyProperty.Register(
        "InputPumpSpeed", typeof(short), typeof(VPWMainVacuumPumpControl), new FrameworkPropertyMetadata((short)0, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// InputLowThreshold
        ///  
        public short InputPumpSpeed
        {
            get
            {
                return (short)this.GetValue(InputPumpSpeedProperty);
            }
            set
            {
                this.SetValue(InputPumpSpeedProperty, value);
            }
        }
        public static readonly DependencyProperty PumpEnableProperty = DependencyProperty.Register(
            "PumpEnable", typeof(bool), typeof(VPWMainVacuumPumpControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// PumpEnable
        ///  
        public bool PumpEnable
        {
            get
            {
                return (bool)this.GetValue(PumpEnableProperty);
            }
            set
            {
                this.SetValue(PumpEnableProperty, value);
            }
        }
        public static readonly DependencyProperty PumpPWREnableProperty = DependencyProperty.Register(
            "PumpPWREnable", typeof(bool), typeof(VPWMainVacuumPumpControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// PumpPWREnable
        ///  
        public bool PumpPWREnable
        {
            get
            {
                return (bool)this.GetValue(PumpPWREnableProperty);
            }
            set
            {
                this.SetValue(PumpPWREnableProperty, value);
            }
        }
        public static readonly DependencyProperty PumpSpeedControlEnableProperty = DependencyProperty.Register(
        "PumpSpeedControlEnable", typeof(bool), typeof(VPWMainVacuumPumpControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// PumpSpeedControlEnable
        ///  
        public bool PumpSpeedControlEnable
        {
            get
            {
                return (bool)this.GetValue(PumpSpeedControlEnableProperty);
            }
            set
            {
                this.SetValue(PumpSpeedControlEnableProperty, value);
            }
        }
        public static readonly DependencyProperty PumpPressureProperty = DependencyProperty.Register(
        "PumpPressure", typeof(double), typeof(VPWMainVacuumPumpControl), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// PumpPressure
        ///  
        public double PumpPressure
        {
            get
            {
                return (double)this.GetValue(PumpPressureProperty);
            }
            set
            {
                this.SetValue(PumpPressureProperty, value);
            }
        }
        #endregion
        [IgnorePropertyChange]
        public ICommand KeyDownCommand
        {
            get;
            private set;
        }
        private void KeyDownAction(object[] param)
        {
            if (param.Length >= 1)
            {
                if (short.TryParse(param[1].ToString(), out short paramValue))
                {
                    if (paramValue < 0 || paramValue > 10)
                    {
                        MessageBox.Show("qualified values 0 ~ 10", "Invalid Speed Input", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        InvokeClient.Instance.Service.DoOperation($"{ModuleName}.VacuumPumpSpeed", paramValue);
                    }
                        
                }
            }
        }
        #region 按钮事件
        #endregion
        private void PumpPWROn_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.VacuumPumpPowerOn");
        }
        private void PumpPWROff_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.VacuumPumpPowerOff");
        }
        private void PumpEnableOn_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.VacuumPumpEnable");
        }
        private void PumpEnableOff_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.VacuumPumpDisable");
        }
        private void PumpControlOn_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.VacuumPumpSpeedEnable");
        }
        private void PumpControlOff_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.VacuumPumpSpeedDisable");
        }
    }
}