using Aitex.Core.Util;
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using MECF.Framework.Common.Account.Permissions;

namespace SicUI.Models.Operations.Gem
{
    public class GemViewModel : SicUIViewModelBase
    {
        public bool IsPermission { get => this.Permission == MenuPermissionEnum.MP_READ_WRITE; }

        [Subscription("GEM.RecvMsgFromHost")]
        public string RecvMsg { get; set; }

        public string SendMsg { get; set; }

        public string SendMsgTextBox { get; set; }

        [Subscription("GEM.CommunicationState")]
        public string CommunicationState { get; set; }

        [Subscription("GEM.ControlMode")]
        public string ControlMode { get; set; }

        [Subscription("GEM.VariableList")]
        public List<Kxware.Connectivity.Remoting.VariableData> VariableList { get; set; }

        [Subscription("GEM.EventList")]
        public List<Kxware.Connectivity.Remoting.EventData> EventList { get; set; }

        [Subscription("GEM.EventInfoList")]
        public List<string> EventInfoList { get; set; }

        [Subscription("GEM.AlarmList")]
        public List<Kxware.Connectivity.Remoting.AlarmData> AlarmList { get; set; }

        [Subscription("GEM.AlarmInfoList")]
        public List<string> AlarmInfoList { get; set; }

        [Subscription("GEM.SequenceRecipeNameList")]
        public List<string> SequenceRecipeNameList { get; set; }

        //[Subscription("GEM.SequenceRecipeContent")]
        public string SequenceRecipeContent { get; set; }

        //[Subscription("GEM.ProgramLog")]
        //public string ProgramLog { get; set; }

        //[Subscription("GEM.SecsLog")]
        //public string SecsLog { get; set; }

        public void SetEnable(bool enable)
        {
            InvokeClient.Instance.Service.DoOperation($"GEM_SetEnable", enable);
        }

        public void SetControlMode(string mode)
        {
            InvokeClient.Instance.Service.DoOperation($"GEM_SetControlMode", mode);
        }

        public void SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            //string sequenceRecipeName = (sender as DataGrid).CurrentCell.Item.ToString();

            //if (!string.IsNullOrEmpty(sequenceRecipeName))
            //{
            //    InvokeClient.Instance.Service.DoOperation($"GEM_SelectSequenceRecipeChanged", sequenceRecipeName);
            //}
        }

        public void SendMessageToHost()
        {
            if (!string.IsNullOrWhiteSpace(SendMsg))
            {
                InvokeClient.Instance.Service.DoOperation($"GEM_SendMessageToHost", SendMsg);
                SendMsgTextBox += $"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}  {SendMsg}\r\n";
                SendMsg = "";
            }
        }

        public void ConfirmHostMessage()
        {
            InvokeClient.Instance.Service.DoOperation($"GEM_TerminalMessageConfirm");
        }

        public void ClearProgramLog()
        {
            InvokeClient.Instance.Service.DoOperation($"GEM_ClearProgramLog");
        }

        public void ClearSecsLog()
        {
            InvokeClient.Instance.Service.DoOperation($"GEM_ClearSecsLog");
        }
    }
}

