
using StammGenerator.Enum;

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

using SewerStammGen.Shared.Domain;
using StammGenerator.Interface;
using StammGenerator.Commands;

namespace StammGenerator.ViewModel
{
    public class MainWindowViewModel : BaseViewModel
    {
        public IMainWindowNavigator Navigator { get; set; }
        public string? Projektnummer { get; set; }
        private readonly IActualState _actualState;
        public BaseViewModel CurrentViewModel => Navigator.CurrentViewModel;

        public ICommand UpdateCurrentViewModelCommand { get; }

        public static string ApplicationTitle
        {
            get => "Stammdatengenerator Version 0.1";
        }

        public MainWindowViewModel(
            IMainWindowNavigator navigator,
            IViewModelAbstractFactory viewModelFactory,
            IActualState actualState
            
            )
        {
            Navigator = navigator;

            UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator, viewModelFactory);
            UpdateCurrentViewModelCommand.Execute(EMainWindowViewType.Home);

            _actualState = actualState;
            

            _actualState.ProjektChanged += ActualState_ProjektChanged;
            _actualState.LoadLastProjekt();

            Navigator.StateChanged += Navigator_StateChanged;
        }

        private void ActualState_ProjektChanged(object? sender, EventArgs e)
        {
            Projektnummer = _actualState.ProjektID.ToString();
            OnPropertyChanged(nameof(Projektnummer));
        }

        private void Navigator_StateChanged()
        {
            OnPropertyChanged(nameof(CurrentViewModel));
        }
    }
}
