using System.Windows;
using System.Windows.Input;
using Valg.EVA.Skanning.ContainerExtensions;
using Valg.EVA.Skanning.UserInterfaceElements.LightBox;
using Valg.EVA.Skanning.UserInterfaceElements.MessageBox;
using Prism.Commands;
using Prism.Events;

namespace Valg.EVA.Skanning.JobManagement.Startup.UI.Signing
{
    public class SigningErrors : ISigningErrors
    {
        private readonly IEventAggregator eventAggregator;
        private readonly ITypedFactory typedFactory;
        private readonly IBuypassBootstrapper buypassBootstrapper;

        public SigningErrors(IEventAggregator eventAggregator, ITypedFactory typedFactory, IBuypassBootstrapper buypassBootstrapper)
        {
            this.eventAggregator = eventAggregator;
            this.typedFactory = typedFactory;
            this.buypassBootstrapper = buypassBootstrapper;
        }

        public void ShowCertificateMissingInformation()
        {
            var resultDialog = typedFactory.Create<IMessageBox>();

            resultDialog.Initialize(
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_SigningCertificateIsMissingTitle,
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_SigningCertificateIsMissingDetails,
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_SigningCertificateMissingSolution,
                MessageBoxType.Warning, solutionCommands: new ICommand[]{new DelegateCommand(() => buypassBootstrapper.AttemptRestartBuypassMiddleware())
                });

            var eventArgs = new LightBoxEventArgs(resultDialog as Window);
            eventAggregator.GetEvent<ShowLightBoxEvent>().Publish(eventArgs);
        }
    }
}
