using BPA.Utility;
using HBLConsole.Service;
using HBLDevice.Coffee;
using HBLDevice.IceCream;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace HBLConsole.Debug
{
    [AddINotifyPropertyChangedInterface]
    internal class ViewModel_MORKIC
    {
        #region 咖啡机
        /// <summary>
        /// 咖啡机状态
        /// </summary>
        public DrCoffeeStatus CoffeeStatus { get; set; }
        /// <summary>
        /// 应用状态
        /// </summary>
        public DrCoffeeAppStatus AppStatus { get; set; }
        public DrCoffeeWarning Warning { get; set; }
        /// <summary>
        /// 故障信息
        /// </summary>
        public DrCoffeeFault CaffeeFault { get; set; }

        public List<string> Coffees { get; set; } = new List<string>();
        public string SelectedCoffee { get; set; }

        public List<string> CoffeeCmds { get; set; } = new List<string>();
        public string SelectedCoffeeCmd { get; set; }
        #endregion

        #region 冰淇淋
        /// <summary>
        /// 预冷温度
        /// </summary>
        public short YLWD { get; set; }
        /// <summary>
        /// 回气温度
        /// </summary>
        public short HQWD { get; set; }
        /// <summary>
        /// 环境温度
        /// </summary>
        public short HJWD { get; set; }
        /// <summary>
        /// 电流
        /// </summary>
        public short DL { get; set; }
        /// <summary>
        /// 电压
        /// </summary>
        public short DY { get; set; }
        /// <summary>
        /// 当前模式
        /// </summary>
        public MORKI_MODE CurrentMode { get; set; }
        /// <summary>
        /// 故障
        /// </summary>
        public MORKI_FAULT IceCreamFault { get; set; }
        /// <summary>
        /// 成型比
        /// </summary>
        public byte CXB { get; set; }
        /// <summary>
        /// 打料完成状态
        /// </summary>
        public string DLCompleted { get; set; }

        public List<string> IceCreamModes { get; set; } = new List<string>();
        public string SelecteIceCreamdMode { get; set; }
        #endregion

        public ViewModel_MORKIC()
        {
            foreach (DrCoffeeDrinksCode code in Enum.GetValues(typeof(DrCoffeeDrinksCode)))
            {
                Coffees.Add(code.ToString());
            }
            SelectedCoffee = Coffees[0];
            foreach (DrCoffeeCommCmd code in Enum.GetValues(typeof(DrCoffeeCommCmd)))
            {
                CoffeeCmds.Add(code.ToString());
            }
            SelectedCoffeeCmd = CoffeeCmds[0];

            foreach (MORKI_MODE code in Enum.GetValues(typeof(MORKI_MODE)))
            {
                IceCreamModes.Add(code.ToString());
            }
            SelecteIceCreamdMode = IceCreamModes[0];



            ThreadOperate.GetInstance.StartLong(new Action(() =>
            {
                CoffeeStatus = MorkCStatus.GetInstance().CoffeeStatus;
                AppStatus = MorkCStatus.GetInstance().AppStatus;
                Warning = MorkCStatus.GetInstance().Warning;
                CaffeeFault = MorkCStatus.GetInstance().Fault;

                YLWD = MorkIStatus.GetInstance().YLWD;
                HQWD = MorkIStatus.GetInstance().HQWD;
                HJWD = MorkIStatus.GetInstance().HJWD;
                DL = MorkIStatus.GetInstance().DL;
                DY = MorkIStatus.GetInstance().DY;
                CurrentMode = MorkIStatus.GetInstance().CurrentMode;
                IceCreamFault = MorkIStatus.GetInstance().Fault;
                CXB = MorkIStatus.GetInstance().CXB;
                DLCompleted = MorkIStatus.GetInstance().DLCompleted?"打料完成":"打料中";
                Thread.Sleep(500);
            }), "MORK IC-状态刷新");
        }

        public void MakeIceCream()
        {
            DischargeEvent dischargeEvent = new DischargeEvent();
            dischargeEvent.Publish();
        }

        public void SetIceCreamModel()
        {
            ModeSetEvent modeSetEvent = new ModeSetEvent();
            modeSetEvent.Mode = (MORKI_MODE)Enum.Parse(typeof(MORKI_MODE), SelecteIceCreamdMode);
            modeSetEvent.Publish();
        }

        public void MakeCoffee()
        {
            new MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)Enum.Parse(typeof(DrCoffeeDrinksCode), SelectedCoffee) }.Publish();
        }

        public void StopMakeCoffee()
        {
            new CancelMakeCoffeeEvent().Publish();
        }

        public void SetCoffeeModel()
        {
            new CoffeeCommCmdEvent() { CommCmd = (DrCoffeeCommCmd)Enum.Parse(typeof(DrCoffeeCommCmd), SelectedCoffeeCmd) }.Publish();
        }
    }
}
