
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Serilog;
using SlnMesnac.WPF.Attribute;
using SlnMesnac.WPF.Page.Generate;
using SlnMesnac.WPF.ViewModel.Base;
using System;
using System.Windows;

namespace SlnMesnac.WPF.ViewModel
{
    [RegisterAsSingletonAttribute]
    public partial class MainWindowViewModel : BaseViewModel
    {
        public readonly SerilogHelper _logger;
        private readonly GenerateControl _generateControl;

        #region 参数定义
        /// <summary>
        /// PLC设备状态
        /// </summary>
        [ObservableProperty]
        private int plcStatus = 0;

        /// <summary>
        /// 登录人员
        /// </summary>
        [ObservableProperty]
        private string otherInfo;

        /// <summary>
        /// 系统标题
        /// </summary>
        [ObservableProperty]
        private string systemTitle = string.Empty;

        [ObservableProperty]
        public System.Windows.Controls.UserControl userContent = new System.Windows.Controls.UserControl();

        /// <summary>
        /// 箱壳扫码器状态
        /// </summary>
        [ObservableProperty]
        private int _shellScannerStatus = 0;

        /// <summary>
        /// 内胆扫码器状态
        /// </summary>
        [ObservableProperty]
        private int _boldScannerStatus = 0;

        #endregion


        public MainWindowViewModel(SerilogHelper logger,GenerateControl generateControl)
        {

            _logger = logger;
            _generateControl = generateControl;

        }

        /// <summary>
        ///  窗体控制
        /// </summary>
        /// <param name="obj"></param>
        [RelayCommand]
        [RequirePermission("FormControl")]
        private void FormControl(object obj)
        {
            try
            {
                string controlType = obj as string;
                switch (controlType)
                {
                    // 关闭当前窗口
                    case "Exit":
                        //Environment.Exit(0);
                        Application.Current.Shutdown();
                        break;
                    case "Generate":
                        UserContent = _generateControl;
                        break;
                    // 还原 或者 最大化当前窗口
                    case "Normal":
                        if (Application.Current.MainWindow.WindowState == WindowState.Normal)
                        {
                            Application.Current.MainWindow.WindowState = WindowState.Maximized;
                            break;
                        }
                        if (Application.Current.MainWindow.WindowState == WindowState.Maximized)
                        {
                            Application.Current.MainWindow.WindowState = WindowState.Normal;
                            break;
                        }
                        break;

                    // 最小化当前窗口
                    case "Minimized":
                        Application.Current.MainWindow.WindowState = WindowState.Minimized;
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                _logger.Error("窗体控制逻辑异常", ex);
            }
        }

        /// <summary>
        /// 界面跳转
        /// </summary>
        [RelayCommand]
        private void ControlOnClick(object obj)
        {
            try
            {
                string info = obj as string;
                //UserContent = inStoreInfoControl;
            }
            catch (Exception ex)
            {
                _logger.Error("界面跳转逻辑异常", ex);
            }
        }

    }
}
