using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using Microsoft.Toolkit.Mvvm.Input;
using Microsoft.Toolkit.Mvvm.Messaging;
using System.Diagnostics;
using HBLConsole.Model;
using HBLConsole.Service;

namespace HBLConsole.DialogWindow.ViewModel
{
    public class DeviceManagermentSetViewModel : ObservableObject
    {
        public DeviceManagermentSetViewModel()
        {
            Init();
            CancelCommand = new RelayCommand(() =>
            {
                ActionOperate.GetInstance.Send("Cancel", devcieManagerResult);
            });
            ConfirmCommand = new RelayCommand(() =>
            {
                var res = ActionOperate.GetInstance.SendResult("AddDeviceVerify", devcieManagerResult);
                if (res != null)
                {
                    if (res is bool blen)
                    {
                        if (blen)
                        {
                            ActionOperate.GetInstance.Send("Confirm", devcieManagerResult);
                        }
                        else
                        {
                            LogInfo = $"警告：设备【{devcieManagerResult.DeviceName}】已存在，请重试";
                        }
                    }
                }
            });
        }

        public ObservableCollection<string> DeviceType { get; set; } = new ObservableCollection<string>();

        public RelayCommand CancelCommand { get; set; }
        public RelayCommand ConfirmCommand { get; set; }

        private void Init()
        {
            DeviceType.Clear();
            foreach (var item in Enum.GetNames(typeof(EDeviceType))) { DeviceType.Add(item); }
        }

        public DeviceManagermentResult devcieManagerResult { get { return _mdevcieManagerResult; } set { _mdevcieManagerResult = value; OnPropertyChanged(); } }
        private DeviceManagermentResult _mdevcieManagerResult = new DeviceManagermentResult();


        public string LogInfo { get { return _mLogInfo; } set { _mLogInfo = value; OnPropertyChanged(); } }
        private string _mLogInfo;




    }
}
