namespace ProximaAnalizer.ViewModels;

internal partial class LoadingViewModel : ObservableObject
{
    public LoadingViewModel(IRegionManager regionManager, IEventAggregator eventAggregator,SqlSugarCustom sqlSugarCustom)
    {
        this._regionManager = regionManager;
        this._eventAggregator = eventAggregator;
        this._sqlSugarCustom = sqlSugarCustom;

        Task.Factory.StartNew(Initialize);
    }

    private readonly IEventAggregator _eventAggregator;
    private readonly IRegionManager _regionManager;
    private readonly SqlSugarCustom _sqlSugarCustom;

    private void Initialize()
    {
        //Thread.Sleep(2000);
        string dbString = "Database=TINReal;Password=123456;Host=10.4.6.87;Username=postgres;Persist Security Info=True";

        this._sqlSugarCustom.Initialize(null);
        if(!this._sqlSugarCustom.Open(dbString, SqlSugar.DbType.PostgreSQL,true))
        {
            MessageBox.Show("Connect to db 10.4.6.87 Failed");
            App.Current.Shutdown();
        }    

        App.Current.Dispatcher.Invoke(() =>
        {
            _eventAggregator.GetEvent<WindowSwitch>().Page = Pages.RecipeStepNavi;
            _eventAggregator.GetEvent<WindowSwitch>().Publish();
        });

    }
}
