using Aitex.Core.UI.MVVM;
using Aitex.Core.Utilities;
using MECF.Framework.Simulator.Core.Commons;
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 MECF.Framework.Simulator.Core.Robots.Sunway
{
    /// <summary>
    /// SunwayWaferRobotView.xaml 的交互逻辑
    /// </summary>
    public partial class SunwayWaferRobotView : UserControl
    {
        public SunwayWaferRobotView()
        {
            InitializeComponent();
            this.DataContext = new SunwayWaferRobotViewModel();

            this.Loaded += OnViewLoaded;
        }

        private void OnViewLoaded(object sender, RoutedEventArgs e)
        {
            (DataContext as TimerViewModelBase).Start();
        }
    }

    class SunwayWaferRobotViewModel : SocketDeviceViewModel
    {
        public string Title => "Sunway Wafer Robot Simulator";

        private SunwayRobotSimulator _robot;
        public bool IsError
        {
            get => _robot.IsError;
            set => _robot.IsError = value;
        }


        //private string _value;

        [IgnorePropertyChange]
        public string ErrorCode
        {
            get => _robot.ErrorCode;

            set => _robot.ErrorCode = value;
        }
        public bool StateChecked
        {
            get => _robot.StateChecked;
            set => _robot.StateChecked = value;
        }

        public int StateCode
        {
            get => _robot.StateCode;
            set => _robot.StateCode = value;
        }
        public bool EventChecked
        {
            get => _robot.EventChecked;

            set
            {
                _robot.EventChecked = value;
                if (value) EventCode = "_EVENT ROBOR 02610 0003 B -00028 000028 000028 -00002\r";
                else EventCode = null;
            }
        }

        [IgnorePropertyChange]
        public string EventCode
        {
            get => _robot.EventCode;
            set => _robot.EventCode = value;
        }
        public SunwayWaferRobotViewModel() : base("SunwayRobotViewModel")
        {
            _robot = new SunwayRobotSimulator(1103);
            Init(_robot);
        }
    }
}
