using System;
using System.Windows.Input;

namespace BodyshopPartner.ViewModels
{
    public partial class MainViewModel : BaseViewModel
    {
        private ICommand _testCommand;
        public ICommand TestCommand
        {
            get
            {
                if (_testCommand == null)
                {
                    _testCommand = new RelayCommand(
                        p => true,
                       async p =>
                        {
                            await TestGql();
                        });
                }
                return _testCommand;
            }
        }

        private ICommand _openMainWindowCommand;
        public ICommand OpenMainWindowCommand
        {
            get
            {
                if (_openMainWindowCommand == null)
                {
                    _openMainWindowCommand = new RelayCommand(
                        p => true,
                        p => Console.WriteLine("nada")
                       ); ;
                }
                return _openMainWindowCommand;
            }
        }

        private ICommand _addMonitoringPathCommand;
        public ICommand AddMonitoringPathCommand
        {
            get
            {
                if (_addMonitoringPathCommand == null)
                {
                    _addMonitoringPathCommand = new RelayCommand(
                        p => true,
                        p => AddFolderMonitoringPath()
                       );
                }
                return _addMonitoringPathCommand;
            }
        }

        private ICommand _removeMonitoringPathCommand;
        public ICommand RemoveMonitoringPathCommand
        {
            get
            {
                if (_removeMonitoringPathCommand == null)
                {
                    _removeMonitoringPathCommand = new RelayCommand(
                        p => true,
                        p => RemoveFolderMonitoringPath(p as Models.Monitor)
                       );
                }
                return _removeMonitoringPathCommand;
            }
        }

        private ICommand _startFolderMonitorsCommand;
        public ICommand StartFolderMonitorsCommand
        {
            get
            {
                if (_startFolderMonitorsCommand == null)
                {
                    _startFolderMonitorsCommand = new RelayCommand(
                        p => MonitoringPaths.Count > 0 && ActiveShop != null,
                        p => StartAllFolderMonitors()
                       ) ;
                }
                return _startFolderMonitorsCommand;
            }
        }

        private ICommand _restartMonitoringPathCommand;
        public ICommand RestartMonitoringPathCommand
        {
            get
            {
                if (_restartMonitoringPathCommand == null)
                {
                    _restartMonitoringPathCommand = new RelayCommand(
                        p => true,
                        p => ((Models.Monitor)p).StartMonitor()
                       );
                }
                return _restartMonitoringPathCommand;
            }
        }

        private ICommand _stopFolderMonitorsCommand;
        public ICommand StopFolderMonitorsCommand
        {
            get
            {
                if (_stopFolderMonitorsCommand == null)
                {
                    _stopFolderMonitorsCommand = new RelayCommand(
                        p => MonitoringPaths.Count > 0,
                        p => StopAllFolderMonitors()
                       );
                }
                return _stopFolderMonitorsCommand;
            }
        }

        private ICommand _browseForQbFolderCommand;
        public ICommand BrowseForQbFolderCommand
        {
            get
            {
                if (_browseForQbFolderCommand == null)
                {
                    _browseForQbFolderCommand = new RelayCommand(
                        p => true,
                        p => BrowseForQbFolder()
                       );
                }
                return _browseForQbFolderCommand;
            }
        }


        private ICommand _installUpdatesCommand;
        public ICommand InstallUpdatesCommand
        {
            get
            {
                if (_installUpdatesCommand == null)
                {
                    _installUpdatesCommand = new RelayCommand(
                        p => UpdateAvailable,
                        async p =>
                        {
                            await InstallUpdates();
                        });
                }
                return _installUpdatesCommand;
            }
        }


        private ICommand _quitCommand;
        public ICommand QuitCommand
        {
            get
            {
                if (_quitCommand == null)
                {
                    _quitCommand = new RelayCommand(
                        p => true,
                        p =>
                       {
                           Properties.Settings.Default.Save(); App.Current.Shutdown(0);
                       });
                }
                return _quitCommand;
            }
        }

    }
}
