using Prism.Commands;
using Prism.Ioc;
using Prism.Mvvm;
using StartServerWPF.Assets;
using StartServerWPF.Models;
using StartServerWPF.Modules.Main.Models;
using StartServerWPF.Modules.Main.ViewModels;
using System;
using System.Windows;

namespace StartServerWPF.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private string _title = "StartServerWPF";
        private readonly IContainerProvider _containerProvider;

        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }      
       public DelegateCommand ExitCommand => new(() =>
        {
            if (MessageBox.Show("是否退出程序？", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {

                Exit();
            }
        });
        public void Exit()
        {
            var main = _containerProvider.Resolve<MainViewModel>();
            var log = new LogMessageModel
            {
                LogType = "系统",
                AppName = "系统",
                State = "程序退出",
                OriginTime = DateTime.Now,
            };
            LogHelper.WriteSerLog(_containerProvider.Resolve<SystemConfigModel>().vpnInfo.SystemLogPath, log.ToString());

            main.OneKeyStop();
            Application.Current.Shutdown();
        }


        public MainWindowViewModel(IContainerProvider containerProvider)
        {
            this._containerProvider = containerProvider;
        }



    }
}
