using System.Windows.Threading;
using Valg.EVA.Skanning.ContainerExtensions;
using Valg.EVA.Skanning.ServicesModel.ServiceContracts.Box.Write.EmptyBox;
using Valg.EVA.Skanning.ServicesModel.ServiceContracts.Count.Write;
using Valg.EVA.Skanning.ServicesModel.ServiceContracts.Scan.Write;
using Valg.EVA.Skanning.UserInterfaceElements.LightBox;
using Valg.EVA.Skanning.UserInterfaceElements.Login;
using Valg.EVA.Skanning.UserInterfaceElements.Spinner;
using Valg.EVA.Skanning.UserInterfaceElements.TopBar;
using Valg.EVA.Skanning.Identity;
using Valg.EVA.Skanning.Scan.ReadSoftContracts.Events;
using Valg.EVA.Skanning.Services.Count;
using Valg.EVA.Skanning.Services.Scan;
using Valg.EVA.Skanning.UserInterfaceElements.MessageBox;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Prism.Commands;
using Prism.Events;
using Valg.Eva.Skanning.Scan.Presentation.BoxInfo;
using Valg.Eva.Skanning.Scan.Presentation.RegisterBarcode;
using Valg.Eva.Skanning.Scan.Presentation.RegisterBarcode.Barcode;
using Valg.Eva.Skanning.Scan.Presentation.ScanInProgress;
using Valg.Eva.Skanning.Scan.Presentation.SelectCountingUnitPopup;
using Valg.EVA.Skanning.Configuration;
using Valg.EVA.Skanning.Contracts.Security;
using Valg.EVA.Skanning.Scan.Presentation.ScannerQuality;
using Valg.EVA.Skanning.Scan.Presentation.StateReporting;
using Valg.EVA.Skanning.Scan.Startup.StateReporting;
using Valg.EVA.Skanning.UserInterfaceElements.Help;
using Valg.EVA.Skanning.UserInterfaceElements;
using Valg.EVA.Skanning.UserInterfaceElements.ApplicationEvents;
using Valg.EVA.Skanning.UserInterfaceElements.ApplicationTermination;
using Valg.EVA.Skanning.UserInterfaceElements.ScannerQuality;
using Valg.EVA.Skanning.UserInterfaceElements.UserSettings;

namespace Valg.Eva.Skanning.Scan.Presentation.MainWindow
{
    public class MainWindowViewModel : ViewModelBase, IMainWindowViewModel
    {
        private readonly ICountingService countingService;
        private readonly IScanService scanService;
        private readonly IIdentityProvider identityProvider;
        private readonly ITypedFactory typedFactory;
        private readonly IBarcodeValidator barcodeValidator;
        private readonly ScanFormFinishedEventHandler scanFormFinishedEventHandler;
        private readonly string windowIcon = "/Valg.EVA.Skanning.Assets;component/Images/Icons/EvaScan.ico";

        private IScannerQualityViewModel scannerQualityViewModel;
        private int currentMainViewIndex;
        private bool IsScannerQualityCheckViewActive => CurrentMainViewIndex == MainTabIndexes.ScannerQualityCheck;
        private BoxScanningSession currentScanningSession;
        private readonly SynchronizationContext _syncContext;


        public MainWindowViewModel(
            ITypedFactory typedFactory,
            ICountingService countingService,
            IScanService scanService,
            IIdentityProvider identityProvider,
            IEventAggregator eventAggregator,
            IRegisterBarcodeViewModel registerBarcodeViewModel,
            IBoxInfoViewModel boxInfoViewModel,
            ILightBoxViewModel lightBoxViewModel,
            IBarcodeValidator barcodeValidator,
            ScanInProgressViewModel scanInProgressViewModel,
            ISpinnerViewModel spinnerViewModel,
            ScanFormFinishedEventHandler scanFormFinishedEventHandler
            )
        {
            this.typedFactory = typedFactory;
            this.countingService = countingService;
            this.scanService = scanService;
            this.identityProvider = identityProvider;
            RegisterBarcodeViewModel = registerBarcodeViewModel;
            BoxInfoViewModel = boxInfoViewModel;
            LightBoxViewModel = lightBoxViewModel;
            this.barcodeValidator = barcodeValidator;
            ScanInProgressViewModel = scanInProgressViewModel;
            SpinnerViewModel = spinnerViewModel;
            this.scanFormFinishedEventHandler = scanFormFinishedEventHandler;
            _syncContext = SynchronizationContext.Current;

            ShowHelpCommand = new DelegateCommand(eventAggregator.ShowHelpWindow);
        }

        protected override void SubscribeToViewModelSpecificEvents()
        {
            SubscribeToEvent<BarcodeCompleteEvent, BarcodeCompleteEventArgs>(BarcodeComplete);
            SubscribeToEvent<StartScanningEvent, StartScanningEventArgs>(HandleStartScanningEvent);
            SubscribeToEvent<SetReadyForAcceptingBarcodesEvent, SetReadyForAcceptingBarcodesEventArgs>(SetReadyForAcceptingBarcodes);
            SubscribeToEvent<DeleteAllInBoxAndScanAgainEvent, DeleteAllInBoxAndScanAgainEventArgs>(DeleteAllAndScanAgainImmediatly);
            SubscribeToEvent<AllBallotPapersAreScannedEvent, AllBallotPapersAreScannedEventArgs>(BoxIsCompletelyScanned);
            SubscribeToEvent<RegisterBoxAsEmptyEvent, RegisterBoxAsEmptyEventArgs>(RegisterBoxAsEmpty);

            SubscribeToEvent<ScanFormFinishedEvent, ScanFormFinishedEventArgs>(HandleScanFormFinishedEvent);
            SubscribeToEvent<ScanReportedNoMorePaperInFeederEvent, ScanReportedNoMorePaperInFeederEventArgs>(HandleScanReportedNoMorePaperInFeeder);
            SubscribeToEvent<ScanReportedUnspecificReadsoftErrorCodeEvent, ScanReportedUnspecificReadsoftErrorCodeEventArgs>(HandleScanReportedUnspecificReadsoftErrorCode);
            SubscribeToEvent<ScanReportedPaperJamEvent, ScanReportedPaperJamEventArgs>(HandleScanReportedPaperJam);

            SubscribeToEvent<LaunchScannerQualityCheckEvent, LaunchScannerQualityCheckEventArgs>(LaunchScannerQualityCheck);
            SubscribeToEvent<MainWindowRequestedEvent, EventArgs>(MainWindowRequested);

            SubscribeToEvent<ScanJobStartedEvent>(ScanJobStarted);
            SubscribeToEvent<ScanJobFinishedEvent>(ScanJobFinished);
        }

        private void ScanJobStarted()
        {
            
        }

        private void ScanJobFinished()
        {
            _syncContext.Post(o =>
            {
                
            }, null);
        }

        public void Initialize(bool isElectionConfigInstalled)
        {
            SetCurrentScanningSession(BoxScanningSession.EmptySession);
            if (isElectionConfigInstalled)
            {
                SetReadyForAcceptingBarcodes(new SetReadyForAcceptingBarcodesEventArgs());
            }
        }

        public ICommand ShowHelpCommand { get; private set; }

        public int CurrentMainViewIndex
        {
            get { return currentMainViewIndex; }
            set
            {
                currentMainViewIndex = value;
                OnPropertyChanged();
                PublishEvent<ScanningMainPageChangedEvent, ScanningMainPageChangedEventArgs>(new ScanningMainPageChangedEventArgs { NewIndex = currentMainViewIndex });
            }
        }

        public IRegisterBarcodeViewModel RegisterBarcodeViewModel { get; }
        public IBoxInfoViewModel BoxInfoViewModel { get; }
        public ILightBoxViewModel LightBoxViewModel { get; }
        public ScanInProgressViewModel ScanInProgressViewModel { get; }
        public ISpinnerViewModel SpinnerViewModel { get; }

        public IScannerQualityViewModel ScannerQualityViewModel
        {
            get { return scannerQualityViewModel; }
            set
            {
                scannerQualityViewModel = value;
                OnPropertyChanged();
            }
        }

        private void SetCurrentScanningSession(BoxScanningSession value)
        {
            currentScanningSession = value;

            if (currentScanningSession == null)
            {
                currentScanningSession = BoxScanningSession.EmptySession;
            }
            else
            {
                BoxInfoViewModel.AttachToModel(currentScanningSession);
                ScanInProgressViewModel.AttachToModel(currentScanningSession);
            }

            if (currentScanningSession == BoxScanningSession.EmptySession)
            {
                PublishEvent<BoxScanningSessionHasBeenResetEvent, BoxScanningSessionHasBeenResetEventArgs>(new BoxScanningSessionHasBeenResetEventArgs());
                PublishEvent<BoxCountingInformationViewChangeVisibilityEvent, BoxCountingInformationViewChangeVisibilityEventArgs>(new BoxCountingInformationViewChangeVisibilityEventArgs(false));
            }
        }

        public void Login()
        {
            var loginProcess = typedFactory.Create<LoginProcessViewModel>();
            var loginResult = loginProcess.Login(ClaimDefinitions.ScanAccessClaimType, windowIcon);

            if (loginResult != LoginResult.AccessGranted)
            {
                CloseApplication();
            }

            RegisterBarcodeViewModel.SetFocusOnFirstBarcode();
            Task.Run(() => SendStateReport());
        }

        private static void SendStateReport()
        {
            var userSettings = new UserSettingsProvider(new System.IO.Abstractions.FileSystem()).GetUserSettings();
            var scannerModel = userSettings.EmulateScanner ? "Emulator" : userSettings.SelectedScannerModel;
            var config = ReadSoftConfiguration.GetDefaultReadSoftConfiguration();
            var connectionString = config.StateReportConnectionString;
            var sink = new SftpReportSink(connectionString);
            var report = StateReport.Create( scannerModel, sink);
            report.GenerateAndSend();

        }
        public void ShowElectionConfigMissingWindow()
        {
            var resultDialog = typedFactory.Create<IMessageBox>();
            resultDialog.Initialize(EVA.Skanning.Resources.Language.ScanLanguageString.ElectionConfigMissingTextPart1, string.Empty, EVA.Skanning.Resources.Language.ScanLanguageString.ElectionConfigMissingTextPart2,
                MessageBoxType.Warning, null, new DelegateCommand(CloseApplication));

            var eventArgs = new LightBoxEventArgs(resultDialog as Window);
            PublishEvent<ShowLightBoxEvent, LightBoxEventArgs>(eventArgs);
        }

        private void MainWindowRequested(EventArgs obj)
        {
            if (IsScannerQualityCheckViewActive)
            {
                SetReadyForAcceptingBarcodes(new SetReadyForAcceptingBarcodesEventArgs());
                ScannerQualityViewModel?.Dispose();
            }
        }

        private void LaunchScannerQualityCheck(LaunchScannerQualityCheckEventArgs obj)
        {
            if (!IsScannerQualityCheckViewActive)
            {
                ScannerQualityViewModel = typedFactory.Create<IScannerQualityViewModel>();
                CurrentMainViewIndex = MainTabIndexes.ScannerQualityCheck;
            }
        }

        private void RegisterBoxAsEmpty(RegisterBoxAsEmptyEventArgs obj)
        {
            var parameters = new RegisterBoxAsEmptyParameters(
                currentScanningSession.Box.BoxCounting.Id,
                currentScanningSession.Box.BoxCounting.ConcurrencyToken,
                identityProvider.GetCurrentUserName(),
                identityProvider.IsInEmergencyMode);

            var result = countingService.RegisterBoxAsEmpty(parameters);

            if (result.RegisterBoxAsEmptyFailed)
            {
                ShowWarningOrErrorsDialog(
                    EVA.Skanning.Resources.Language.ScanLanguageString.RegisterBoxAsEmptyFailedTitle,
                    EVA.Skanning.Resources.Language.ScanLanguageString.RegisterBoxAsEmptySolution);
            }
            else
            {
                ShowBoxWasRegisteredAsEmptyDialog();
            }
            SetReadyForAcceptingBarcodes(new SetReadyForAcceptingBarcodesEventArgs());
        }

        private void BoxIsCompletelyScanned(AllBallotPapersAreScannedEventArgs obj)
        {
            var boxCounting = currentScanningSession.Box.BoxCounting;
            var uiDispatcher = Dispatcher.CurrentDispatcher;

            
            AttemptPostProcessingOfBox(new BoxIsCompletelyScannedParameters(
                boxCounting.BarcodeLong,
                boxCounting.BarcodeShort,
                currentScanningSession.CountingId,
                boxCounting.ConcurrencyToken,
                identityProvider.GetCurrentUserName(),
                currentScanningSession.CountingEmlAreaContextId,
                identityProvider.IsInEmergencyMode),
                boxCounting.Id, uiDispatcher);

            
            SetReadyForAcceptingBarcodes(new SetReadyForAcceptingBarcodesEventArgs());
        }

        private void AttemptPostProcessingOfBox(BoxIsCompletelyScannedParameters parameters, int boxCountingId, Dispatcher uiDispatcher)
        {
            var processRunner = typedFactory.Create<ProcessRunner>();
            processRunner
                .Run(() =>
                {
                    var result = scanService.BoxIsCompletelyScanned(parameters);

                    if (result.OperationResult == BoxIsCompletelyScannedOperationResult.BoxDeleted)
                    {
                        uiDispatcher.Invoke(ShowCountingDeletedErrorMessage);
                    }
                    else if (result.OperationResult == BoxIsCompletelyScannedOperationResult.InterpretFailed
                             || result.OperationResult == BoxIsCompletelyScannedOperationResult.DuplicateDetectionFailed)
                    {
                        uiDispatcher.Invoke(() => ShowDialogForReattemptPostProcessingOfBox(result, parameters, boxCountingId, uiDispatcher));
                    }
                },
                EVA.Skanning.Resources.Language.ScanLanguageString.BoxComplete_SpinnerTitle,
                EVA.Skanning.Resources.Language.ScanLanguageString.BoxComplete_SpinnerText);
        }

        private void ShowDialogForReattemptPostProcessingOfBox(BoxIsCompletelyScannedResult result, BoxIsCompletelyScannedParameters parameters, int boxCountingId, Dispatcher uiDispatcher)
        {
            var resultDialog = typedFactory.Create<IMessageBox>();

            resultDialog.Initialize(EVA.Skanning.Resources.Language.ScanLanguageString.PostProcessingOfBallotsAfterScanFailed,
                EVA.Skanning.Resources.Language.ScanLanguageString.CouldNotFinishPostProcessingAfterScanning,
                EVA.Skanning.Resources.Language.ScanLanguageString.PostProcessingFailedSolutions,
                MessageBoxType.Warning,
                result.PossibleException != null ? new[] { result.PossibleException } : null,
                solutionCommands: new ICommand[]
                {
                    new DelegateCommand(() =>
                    {
                        resultDialog.CloseWindow();
                        AttemptPostProcessingOfBox(parameters, boxCountingId, uiDispatcher);
                    })
                },
                cancelCommand: new DelegateCommand(() =>
                {
                    var boxCounting = scanService.GetBoxCountingById(boxCountingId);
                    countingService.DeleteBoxCountingAndReregisterForScanning(new DeleteBoxCountingAndReregisterForScanningParameters(parameters.BarcodeLong, parameters.BarcodeShort,
                        parameters.CountingId, false, boxCounting.ConcurrencyToken, parameters.CountingEmlAreaContextId, parameters.CompletedByUser));
                }));

            PublishEvent<ShowLightBoxEvent, LightBoxEventArgs>(new LightBoxEventArgs(resultDialog as Window));
        }

        private void ShowCountingDeletedErrorMessage()
        {
            var messageBox = typedFactory.Create<IMessageBox>();

            messageBox.Initialize(
                EVA.Skanning.Resources.Language.ScanLanguageString.Warning_CountingIsDeleted_Title,
                EVA.Skanning.Resources.Language.ScanLanguageString.Warning_CountingIsDeleted_Info,
                MessageBoxType.Warning);

            PublishEvent<ShowLightBoxEvent, LightBoxEventArgs>(new LightBoxEventArgs(messageBox as Window));
        }

        private void DeleteAllAndScanAgainImmediatly(DeleteAllInBoxAndScanAgainEventArgs args)
        {
            var barcodeLong = currentScanningSession.Box.BoxCounting.BarcodeLong;
            var barcodeShort = currentScanningSession.Box.BoxCounting.BarcodeShort;

            var deleteAndReregisterResult = countingService.DeleteBoxCountingAndReregisterForScanning(
                new DeleteBoxCountingAndReregisterForScanningParameters(
                    barcodeLong,
                    barcodeShort,
                    currentScanningSession.CountingId,
                    args.ScanAgainImmediatly,
                    currentScanningSession.Box.BoxCounting.ConcurrencyToken,
                    currentScanningSession.CountingEmlAreaContextId,
                    identityProvider.GetCurrentUserName()));

            if (deleteAndReregisterResult.CountingIsNotActive || deleteAndReregisterResult.DeleteAndReregisterFailed)
            {
                PublishEvent<BoxIsDeletedDuringScanEvent, EventArgs>(EventArgs.Empty);
            }
            else
            {
                if (args.ScanAgainImmediatly)
                {
                    currentScanningSession.ResetSessionData();
                    currentScanningSession.ReloadBoxModel(barcodeLong, barcodeShort);
                    RequestStartScanJob();
                }
                else
                {
                    SetReadyForAcceptingBarcodes(new SetReadyForAcceptingBarcodesEventArgs());
                }
            }
        }

        private void HandleScanFormFinishedEvent(ScanFormFinishedEventArgs eventArgs)
        {
            if (IsScannerQualityCheckViewActive)
            {
                ScannerQualityViewModel.RunQualityCheck(eventArgs);
            }
            else
            {
                scanFormFinishedEventHandler.SaveBallotPaper(eventArgs, currentScanningSession);
            }
        }

        private void HandleScanReportedPaperJam(ScanReportedPaperJamEventArgs obj)
        {
            if (IsScannerQualityCheckViewActive)
            {
                ScannerQualityViewModel.HandleScanReportedPaperJam(obj);
            }
            else
            {
                ScanInProgressViewModel.HandleScanReportedPaperJam(obj);
            }
        }

        private void HandleScanReportedUnspecificReadsoftErrorCode(ScanReportedUnspecificReadsoftErrorCodeEventArgs obj)
        {
            if (IsScannerQualityCheckViewActive)
            {
                ScannerQualityViewModel.HandleScanReportedUnspecificReadsoftErrorCode(obj);
            }
            else
            {
                ScanInProgressViewModel.HandleScanReportedUnspecificReadsoftErrorCode(obj);
            }
        }

        private void HandleScanReportedNoMorePaperInFeeder(ScanReportedNoMorePaperInFeederEventArgs obj)
        {
            if (IsScannerQualityCheckViewActive)
            {
                ScannerQualityViewModel.HandleScanReportedNoMorePaperInFeeder(obj);
            }
            else
            {
                ScanInProgressViewModel.HandleScanReportedNoMorePaperInFeeder(obj);
            }
        }


        private void SetReadyForAcceptingBarcodes(SetReadyForAcceptingBarcodesEventArgs setReadyForAcceptingBarcodesEventArgs)
        {
            RegisterBarcodeViewModel.ClearBarcodes();

            SetCurrentScanningSession(BoxScanningSession.EmptySession);

            CurrentMainViewIndex = MainTabIndexes.RegisterBarcodesPageIndex;

            RegisterBarcodeViewModel.SetFocusOnFirstBarcode();
        }

        private void RequestStartScanJob()
        {
            
            PublishEvent<ScanJobRequestedStartedEvent, ScanJobRequestedStartedEventArgs>(new ScanJobRequestedStartedEventArgs());
        }

        private void HandleStartScanningEvent(StartScanningEventArgs startScanningEventArgs)
        {
            CurrentMainViewIndex = MainTabIndexes.ScanInProgressPageIndex;

            var barcodeLong = currentScanningSession.Box.BoxCounting.BarcodeLong;
            var barcodeShort = currentScanningSession.Box.BoxCounting.BarcodeShort;

            var startScanningResult = scanService.StartScanning(new StartScanningParameters(barcodeLong,
                barcodeShort, currentScanningSession.CountingId, currentScanningSession.Box.BoxCounting.ConcurrencyToken, identityProvider.GetCurrentUserName()));

            if (startScanningResult.CountingIsNotActive || startScanningResult.BoxIsNotReadyForScan)
            {
                PublishEvent<BoxIsDeletedDuringScanEvent, EventArgs>(EventArgs.Empty);
            }
            else
            {
                currentScanningSession.ReloadBoxModel(barcodeLong, barcodeShort);
                RequestStartScanJob();
            }
        }

        private void BarcodeComplete(BarcodeCompleteEventArgs eventArgs)
        {
            var validationResult = barcodeValidator.Validate(new Barcode { BarcodeLong = eventArgs.BarcodeLong, BarcodeShort = eventArgs.BarcodeShort });
            if (validationResult.IsValid)
            {
                var reportingUnits = GetReportingUnits(eventArgs);

                if (reportingUnits.HasMoreThanOnescannableCounting)
                {
                    ShowSelectCountingPopup(
                        eventArgs.BarcodeLong,
                        eventArgs.BarcodeShort,
                        reportingUnits);
                }
                else
                {
                    LoadCounting(
                        eventArgs.BarcodeLong,
                        eventArgs.BarcodeShort,
                        reportingUnits.FirstCountingEmlAreaContextId);
                }
            }
            else
            {
                ShowWarningOrErrorsDialog(
                    EVA.Skanning.Resources.Language.ScanLanguageString.BarcodesAreNotValid,
                    EVA.Skanning.Resources.Language.ScanLanguageString.SuggestRecheckBarcodes);
                RegisterBarcodeViewModel.ClearBarcodes();
                RegisterBarcodeViewModel.SetFocusOnFirstBarcode();
            }
        }

        private void ShowSelectCountingPopup(
            string barcodeLong,
            string barcodeShort,
            CountingUnitCollection reportingUnits)
        {
            var viewModel = new SelectCountingUnitViewModel(
                reportingUnits,
                unit => LoadCounting(
                    barcodeLong,
                    barcodeShort,
                    unit.CountingEmlAreaContextId));

            var eventArgs = new LightBoxEventArgs(
                typeof(SelectCountingUnitView),
                viewModel);

            PublishEvent<ShowLightBoxEvent, LightBoxEventArgs>(eventArgs);
        }

        private void LoadCounting(
            string barcodeLong,
            string barcodeShort,
            string countingEmlAreaContextId)
        {
            var registerResult = scanService.RegisterBoxForCounting(
               new RegisterBoxForCountingParameters
               {
                   BarcodeLong = barcodeLong,
                   BarcodeShort = barcodeShort,
                   CountingEmlAreaContextId = countingEmlAreaContextId,
                   ChangedBy = identityProvider.GetCurrentUserName(),
                   IsInEmergencyMode = identityProvider.IsInEmergencyMode
               });

            if (registerResult.BoxIsReadyForScan)
            {
                LoadBoxCountingAndSetCurrentScanningSession(
                    barcodeLong,
                    barcodeShort,
                    registerResult.CountingId,
                    countingEmlAreaContextId);
                CurrentMainViewIndex = MainTabIndexes.BoxInfoPageIndex;
            }
            else
            {
                ShowWarningOrErrorsDialog(
                    EVA.Skanning.Resources.Language.ScanLanguageString.Label_BoxNotReadyForScan,
                    EVA.Skanning.Resources.Language.ScanLanguageString.SuggestRecheckBoxStatus);
                RegisterBarcodeViewModel.SetFocusOnFirstBarcode();
                Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.ContextIdle, (Action)(() => RegisterBarcodeViewModel.ClearBarcodes()));
            }
        }

        private CountingUnitCollection GetReportingUnits(BarcodeCompleteEventArgs eventArgs)
        {
            var countings = scanService.GetScannableCountings(
                eventArgs.BarcodeLong,
                eventArgs.BarcodeShort);

            return new CountingUnitCollection(countings);
        }

        private void LoadBoxCountingAndSetCurrentScanningSession(
            string barcodeLong,
            string barcodeShort,
            int countingId,
            string countingEmlAreaContextId)
        {
            var boxScanningSession = new BoxScanningSession(
                countingId,
                scanService,
                countingEmlAreaContextId);

            boxScanningSession.ReloadBoxModel(
                barcodeLong,
                barcodeShort);

            SetCurrentScanningSession(boxScanningSession);
        }

        private void ShowWarningOrErrorsDialog(string warningsOrErrorsToDisplay, string suggestion = null)
        {
            ShowWarningOrErrorsDialog(
                warningsOrErrorsToDisplay,
                new List<string>
                {
                    suggestion
                });
        }

        private void ShowWarningOrErrorsDialog(string warningsOrErrorsToDisplay, List<string> suggestions)
        {
            var messageBox = typedFactory.Create<IMessageBox>();

            messageBox.Initialize(
                warningsOrErrorsToDisplay,
                string.Empty,
                suggestions.ToArray(),
                MessageBoxType.Warning);

            PublishEvent<ShowLightBoxEvent, LightBoxEventArgs>(new LightBoxEventArgs(messageBox as Window));
        }

        private void CloseApplication()
        {
            PublishEvent<ApplicationTerminateRequestedEvent, EventArgs>(EventArgs.Empty);
        }

        private void ShowBoxWasRegisteredAsEmptyDialog()
        {
            var messageBox = typedFactory.Create<IMessageBox>();

            messageBox.Initialize(EVA.Skanning.Resources.Language.ScanLanguageString.BoxWasRegisteredAsEmptyTitle, EVA.Skanning.Resources.Language.ScanLanguageString.BoxWasRegisteredAsEmptyDetails, MessageBoxType.Information);

            PublishEvent<ShowLightBoxEvent, LightBoxEventArgs>(new LightBoxEventArgs(messageBox as Window));
        }
    }
}
