using MainShell.Common;
using MaxwellFramework.Core.Attributes;
using Stylet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MainShell
{
    [Singleton]
    public class MachineState : PropertyChangedBase
    {
        private readonly object _sync = new object();

        private MachineMode _currentMode = MachineMode.Manual;
        private bool _isExiting = false;

        public MachineMode CurrentMode
        {
            get { lock (_sync) { return _currentMode; } }
            set
            {
                bool changed;
                lock (_sync)
                {
                    changed = _currentMode != value;
                    _currentMode = value;
                }
                // 在锁外触发通知，避免死锁
                if (changed)
                    NotifyOfPropertyChange(nameof(CurrentMode));
            }
        }

        public bool IsExiting
        {
            get { lock (_sync) { return _isExiting; } }
            set
            {
                bool changed;
                lock (_sync)
                {
                    changed = _isExiting != value;
                    _isExiting = value;
                }
                if (changed)
                    NotifyOfPropertyChange(nameof(IsExiting));
            }
        }
    }
}
