using HandyControl.Controls;
using Ping9719.WpfEx;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Markup;
using WCS.Model;
using WCS.Model.ApiModel.Home;
using 智慧物流软件系统.Api;

namespace 智慧物流软件系统.ViewModel
{
    public class DeviceViewModel : BindableBase
    {
        public ICommand ResetAllShelfCommand { get => new DelegateCommand(ResetAllShelf); }
        /// <summary>
        /// 打开用户
        /// </summary>
        public void ResetAllShelf()
        {
            #region 调用接口 请求重置所有货架的状态
            var body = new ResetShelfStatusRequest()
            {
                IsResetAll = true,
                GroupNames = LocalFile.Config.GroupName,
                UserName = LocalStatic.CurrentUser,
                DeviceType = LocalFile.Config.DeviceType,
            };
            var Result = ApiHelp.GetDataFromHttp<ResponseBase>(LocalFile.Config.ApiIpHost + "home/resetShelfStatus", body, "POST");
            if (Result != null && Result.Code == 200)
            {
                Growl.Warning("复位成功！");
            }
            else if (Result != null)
            {
                Growl.Warning(Result.Message);
            }
            else
            {
                Growl.Warning("调用接口失败！");
            }
            #endregion
        }


        public ICommand BarcodePrintTemplateCommand { get => new DelegateCommand(BarcodePrintTemplate); }
        public void BarcodePrintTemplate()
        {
            try
            {
                Folder.OpenFolderAndSelectedFile(LocalFile.PrintTemplatePath);
            }
            catch (Exception)
            {
                Growl.Error("打开文件夹失败。");
            }
        }
    }

    public class DeviceReadModel : BindableBase
    {
        #region 属性
        private string Name_;
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get => Name_; set { SetProperty(ref Name_, value); } }

        private object Value_;
        /// <summary>
        /// 值
        /// </summary>
        public object Value { get => Value_; set { SetProperty(ref Value_, value); } }

        /// <summary>
        /// 是否可见
        /// </summary>
        public bool IsExpanded { get; set; }

        /// <summary>
        /// Excel原始数据
        /// </summary>
        public ExcelDeviceReadModel ExcelTag { get; set; }
        #endregion
    }

    public class DeviceWriteModel : BindableBase
    {
        #region 属性
        private string Name_;
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get => Name_; set { SetProperty(ref Name_, value); } }

        private object Value_;
        /// <summary>
        /// 是否合格
        /// </summary>
        public object Value { get => Value_; set { SetProperty(ref Value_, value); } }

        /// <summary>
        /// 是否可见
        /// </summary>
        public bool IsExpanded { get; set; }

        /// <summary>
        /// Excel原始数据
        /// </summary>
        public ExcelDeviceWriteModel ExcelTag { get; set; }
        #endregion
    }

    public class DeviceUrnModel : BindableBase
    {
        #region 属性
        private string Name_;
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get => Name_; set { SetProperty(ref Name_, value); } }

        private bool IsGoTo_;
        /// <summary>
        /// 是否推到位
        /// </summary>
        public bool IsGoTo { get => IsGoTo_; set { SetProperty(ref IsGoTo_, value); } }

        private bool IsRetTo_;
        /// <summary>
        /// 是否回到位
        /// </summary>
        public bool IsRetTo { get => IsRetTo_; set { SetProperty(ref IsRetTo_, value); } }

        /// <summary>
        /// 是否可见
        /// </summary>
        public bool IsExpanded { get; set; }

        /// <summary>
        /// 自定义数据
        /// </summary>
        public ExcelDeviceUrnModel ExcelTag { get; set; }
        #endregion
    }

    public class DeviceServoModel : BindableBase
    {
        #region 属性
        private string Name_;
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get => Name_; set { SetProperty(ref Name_, value); } }

        private double JogSpeed_;
        /// <summary>
        /// 手动模式速度
        /// </summary>
        public double JogSpeed { get => JogSpeed_; set { SetProperty(ref JogSpeed_, value); } }

        private double AutoSpeed_;
        /// <summary>
        /// 自动模式速度
        /// </summary>
        public double AutoSpeed { get => AutoSpeed_; set { SetProperty(ref AutoSpeed_, value); } }

        private double Location_;
        /// <summary>
        /// 伺服当前位置
        /// </summary>
        public double Location { get => Location_; set { SetProperty(ref Location_, value); } }

        private bool IsJog_ = true;
        /// <summary>
        /// 是否主页显示为手动模式
        /// </summary>
        public bool IsJog { get => IsJog_; set { SetProperty(ref IsJog_, value); } }

        private bool IsFold_ = true;
        /// <summary>
        /// 是否折叠
        /// </summary>
        public bool IsFold { get => IsFold_; set { SetProperty(ref IsFold_, value); } }

        /// <summary>
        /// 是否可见
        /// </summary>
        public bool IsExpanded { get; set; }

        private ExcelDeviceServoModel ExcelTag_;
        /// <summary>
        /// 自定义数据
        /// </summary>
        public ExcelDeviceServoModel ExcelTag { get => ExcelTag_; set { SetProperty(ref ExcelTag_, value); } }
        #endregion
    }
}
