using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using SmartAquaViewer.Controls;

namespace SmartAquaViewer.ViewModel
{
    public class MainViewModel : INotifyPropertyChanged
    {
        private object? _selectedViewModel;
        public object? SelectedViewModel
        {
            get => _selectedViewModel;
            set
            {
                if (_selectedViewModel != value)
                {
                    _selectedViewModel = value;
                    OnPropertyChanged(nameof(SelectedViewModel));
                }
            }
        }

        public ICommand SwapViewCommand { get; }

        public MainViewModel()
        {
            SwapViewCommand = new RelayCommand(SwapView);

            SelectedViewModel = new MonitoringViewModel(); // Default view
        }

        private void SwapView(object obj)
        {
            var tag = (string)obj;

            switch (tag)
            {
                case "monitoring":
                    SelectedViewModel = new MonitoringViewModel();
                    break;
                case "energy":
                    SelectedViewModel = new EnergyViewModel();
                    break;
                case "greenHouseGas":
                    SelectedViewModel = new GreenHouseGasViewModel();
                    break;
                case "cctv":
                    SelectedViewModel = new CCTVViewModel();
                    break;
                default:
                    throw new ArgumentException("Unknown view tag", nameof(obj));                
            }
        }

        public event PropertyChangedEventHandler? PropertyChanged;
        private void OnPropertyChanged([CallerMemberName] string? name = null)
            => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    }
}
