using Avalonia;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using detect.gui.Drivers;
using detect.gui.Services;
using detect.gui.Services.Detect;
using detect.gui.ViewModels;
using detect.gui.VWMS;
using detect.gui.VWS;
using ReactiveUI;
using Splat;

namespace detect.gui;

public class App : Application
{
    public override void Initialize() => AvaloniaXamlLoader.Load(this);
        
    public override void OnFrameworkInitializationCompleted()
    {
        var suspension = new AutoSuspendHelper(ApplicationLifetime!);
        RxApp.SuspensionHost.CreateNewAppState = () => new MainViewModel();
        RxApp.SuspensionHost.SetupDefaultSuspendResume(new NewtonsoftJsonSuspensionDriver("app.state.json"));
        suspension.OnFrameworkInitializationCompleted();
        
        Locator.CurrentMutable.Register(DetectUserService.Instance, typeof(DetectUserService));
        Locator.CurrentMutable.Register(DetectAuthorityService.Instance, typeof(DetectAuthorityService));
        Locator.CurrentMutable.Register(DetectDeviceService.Instance, typeof(DetectDeviceService));
        Locator.CurrentMutable.Register( DetectTaskService.Instance, typeof(DetectTaskService));
        Locator.CurrentMutable.Register(DetectTaskLogService.Instance, typeof(DetectTaskLogService));
        Locator.CurrentMutable.Register(DetectTaskProgressService.Instance, typeof(DetectTaskProgressService));
        Locator.CurrentMutable.Register(DetectLogService.Instance, typeof(DetectLogService));
        
        Locator.CurrentMutable.Register(DeviceClientService.Instance, typeof(DeviceClientService));
        Locator.Current.GetService<DeviceClientService>();

        // Locator.CurrentMutable.Register(OCRService.Instance, typeof(OCRService));
        // Locator.Current.GetService<OCRService>();
        
        Locator.CurrentMutable.Register(MainWindowModel.Instance, typeof(MainWindowModel));
        Locator.Current.GetService<MainWindowModel>();
        
        Locator.CurrentMutable.Register(LoginControlModel.Instance, typeof(LoginControlModel));
        
        Locator.CurrentMutable.Register(NotificationWindow.Instance, typeof(NotificationWindow));
        
        Locator.CurrentMutable.Register(MainWindow.Instance, typeof(MainWindow));
        Locator.Current.GetService<MainWindow>()!.Show();

        base.OnFrameworkInitializationCompleted();
    }
}