using Prism.Commands;
using Prism.Mvvm;
using System.Collections.ObjectModel;
using Serilog;

namespace XplorePlane.ViewModels
{
    public class MainViewModel : BindableBase
    {
        private readonly ILogger _logger;
        private string _licenseInfo = "当前时间";

        public string LicenseInfo
        {
            get => _licenseInfo;
            set => SetProperty(ref _licenseInfo, value);
        }

        public ObservableCollection<object> NavigationTree { get; set; }

        public DelegateCommand NavigateHomeCommand { get; set; }
        public DelegateCommand NavigateInspectCommand { get; set; }
        public DelegateCommand OpenFileCommand { get; set; }
        public DelegateCommand ExportCommand { get; set; }
        public DelegateCommand ClearCommand { get; set; }
        public DelegateCommand EditPropertiesCommand { get; set; }
        public DelegateCommand OpenImageProcessingCommand { get; set; }
        public DelegateCommand OpenPipelineEditorCommand { get; set; }

        public MainViewModel(ILogger logger)
        {
            _logger = logger?.ForContext<MainViewModel>() ?? throw new System.ArgumentNullException(nameof(logger));

            NavigationTree = new ObservableCollection<object>();
            
            NavigateHomeCommand = new DelegateCommand(OnNavigateHome);
            NavigateInspectCommand = new DelegateCommand(OnNavigateInspect);
            OpenFileCommand = new DelegateCommand(OnOpenFile);
            ExportCommand = new DelegateCommand(OnExport);
            ClearCommand = new DelegateCommand(OnClear);
            EditPropertiesCommand = new DelegateCommand(OnEditProperties);
            OpenImageProcessingCommand = new DelegateCommand(() =>
            {
                var window = new Views.ImageProcessingWindow();
                window.Show();
                _logger.Information("图像处理窗口已打开");
            });

            OpenPipelineEditorCommand = new DelegateCommand(() =>
            {
                var window = new Views.PipelineEditorWindow();
                window.Show();
                _logger.Information("流水线编辑器窗口已打开");
            });

            _logger.Information("MainViewModel 已初始化");
        }

        private void OnNavigateHome()
        {
            _logger.Information("导航到主页");
            LicenseInfo = "主页";
        }

        private void OnNavigateInspect()
        {
            _logger.Information("导航到检测页面");
            LicenseInfo = "检测页面";
        }

        private void OnOpenFile()
        {
            _logger.Information("打开文件");
            LicenseInfo = "打开文件";
        }

        private void OnExport()
        {
            _logger.Information("导出数据");
            LicenseInfo = "导出数据";
        }

        private void OnClear()
        {
            _logger.Information("清除数据");
            LicenseInfo = "清除数据";
        }

        private void OnEditProperties()
        {
            _logger.Information("编辑属性");
            LicenseInfo = "编辑属性";
        }
    }
}
