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

namespace SlnMesnac.WPF.ViewModel
{
    public partial class MainWindowViewModel: ObservableObject
    {
        public readonly SerilogHelper _logger;

        //代码生成
        private readonly GenerateControl generateControl = new GenerateControl();

        #region 参数定义
        /// <summary>
        /// PLC设备状态
        /// </summary>
        private int _PlcStatus = 0;
        public int PlcStatus
        {
            get => _PlcStatus;
            set => SetProperty(ref _PlcStatus, value);
        }
        /// <summary>
        /// 箱壳扫码器状态
        /// </summary>
        private int _ShellScannerStatus = 0;
        public int ShellScannerStatus
        {
            get => _ShellScannerStatus;
            set => SetProperty(ref _ShellScannerStatus, value);
        }

        /// <summary>
        /// 内胆扫码器状态
        /// </summary>
        private int _BoldScannerStatus = 0;
        public int BoldScannerStatus
        {
            get => _BoldScannerStatus;
            set => SetProperty(ref _BoldScannerStatus, value);
        }

        public System.Windows.Controls.UserControl _content;

        public System.Windows.Controls.UserControl UserContent
        {
            get => _content;
            set => SetProperty(ref _content, value);
        }
        #endregion

        #region 事件定义
        /// <summary>
        /// 打开系统键盘
        /// </summary>
        public RelayCommand OpenSystemKeyboardCommand { get; set; }

        #endregion

        public MainWindowViewModel()
        {

            _logger = App.ServiceProvider.GetService<SerilogHelper>();


        }

        /// <summary>
        ///  窗体控制
        /// </summary>
        /// <param name="obj"></param>
        [RelayCommand]
        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);
            }
        }

    }
}
