using Valg.EVA.Skanning.ContainerExtensions;
using Valg.EVA.Skanning.UserInterfaceElements.MessageBox;
using Unity;
using System.Diagnostics.CodeAnalysis;
using System.IO.Abstractions;
using Prism.Events;
using Valg.EVA.Skanning.UserInterfaceElements.ApplicationTermination;
using Valg.EVA.Skanning.UserInterfaceElements.BrowserLaunch;
using Valg.EVA.Skanning.UserInterfaceElements.ErrorHandling;
using Valg.EVA.Skanning.UserInterfaceElements.Language;
using Valg.EVA.Skanning.UserInterfaceElements.UserSettings;
using Valg.EVA.Skanning.UserInterfaceElements.BallotPaperImage;
using Valg.EVA.Skanning.UserInterfaceElements.DatabaseVerifier;
using Valg.EVA.Skanning.UserInterfaceElements.EmergencyMode;
using Valg.EVA.Skanning.UserInterfaceElements.Help;
using Valg.EVA.Skanning.UserInterfaceElements.LightBox;
using Valg.EVA.Skanning.UserInterfaceElements.Login;
using Valg.EVA.Skanning.UserInterfaceElements.MainWindowProvider;
using Valg.EVA.Skanning.UserInterfaceElements.RoleSelector;
using Valg.EVA.Skanning.UserInterfaceElements.Spinner;
using Valg.EVA.Skanning.UserInterfaceElements.TopBar;
using Valg.EVA.Skanning.UserInterfaceElements.UserSettingWindow;

namespace Valg.EVA.Skanning.UserInterfaceElements
{
    [ExcludeFromCodeCoverage]
    public class UnityInstaller : IUnityInstaller
    {
        [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        public void Install(IUnityContainer unityContainer)
        {
            unityContainer.AddExtension(new LanguageChangeNotifierExtension());

            unityContainer.RegisterType<IEventAggregator, EventAggregator>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<IFileSystem, FileSystem>(ContainerLifetimes.CreateContainerControlledLifetimeManager());

            unityContainer.RegisterType<IUserSettingsProvider, UserSettingsProvider>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<IMessageBox, MessageBox.MessageBox>();
            unityContainer.RegisterType<IMessageBoxViewModel, MessageBoxViewModel>();
            unityContainer.RegisterType<IUserSettingWindow, UserSettingWindow.UserSettingWindow>();
            unityContainer.RegisterType<IUserSettingWindowViewModel, UserSettingWindowViewModel>();
            unityContainer.RegisterType<ApplicationUnhandledExceptionHandler>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<IBrowserLauncher, BrowserLauncher>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<IExceptionConverter, ExceptionConverter>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<IGenericStartupErrorHandler, GenericStartupErrorHandler>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<IDatabaseConsistencyVerifier, DatabaseConsistencyVerifier>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<ApplicationTerminationHandler>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<LoginWindow>();
            unityContainer.RegisterType<ILoginWindowViewModel, LoginWindowViewModel>();            
            unityContainer.RegisterType<ILightBoxViewModel, LightBoxViewModel>();
            unityContainer.RegisterType<ISpinnerViewModel, SpinnerViewModel>();
            unityContainer.RegisterType<IMainWindowProvider, MainWindowProvider.MainWindowProvider>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<IRoleSelectorViewModel, RoleSelectorViewModel>();
            unityContainer.RegisterType<IChangeRoleButtonViewModel, ChangeRoleButtonViewModel>();
            unityContainer.RegisterType<LanguageUIInitiator>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<ILanguageManager, LanguageManager>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<BoxCountingInformationViewModel>();
            unityContainer.RegisterType<IBallotPaperImageViewModel, BallotPaperImageViewModel>();
            unityContainer.RegisterType<IBallotPaperImageWindowProvider, BallotPaperImageWindowProvider>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<IBallotPaperImageWindow, BallotPaperImageWindow>();
            unityContainer.RegisterType<IBallotPaperImageLoader, BallotPaperImageLoader>();
            unityContainer.RegisterType<EmergencyModeConfigurationWindow>();
            unityContainer.RegisterType<EmergencyModeConfigurationWindowViewModel>();
            unityContainer.RegisterType<IHelpProvider, HelpProvider>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
            unityContainer.RegisterType<IEmergencyModeLoginViewModel, EmergencyModeLoginViewModel>();
            unityContainer.RegisterType<HelpViewModel>();
            unityContainer.RegisterType<EmergencyModeLoginWindow>();
            unityContainer.RegisterType<IWaitCursorProvider, WaitCursorProvider>(ContainerLifetimes.CreateContainerControlledLifetimeManager());
        }
    }
}
