using Valg.EVA.Skanning.ContainerExtensions;
using Valg.EVA.Skanning.ServicesModel.ServiceContracts.SystemServices.Read;
using Valg.EVA.Skanning.UserInterfaceElements.Spinner;
using Valg.EVA.Skanning.Services.SystemServices;

namespace Valg.Eva.Skanning.Scan.Presentation.MainWindow
{
    public class DatabaseQuerier
    {
        private readonly ISystemService systemService;
        private readonly ITypedFactory typedFactory;

        public DatabaseQuerier(ISystemService systemService, ITypedFactory typedFactory)
        {
            this.systemService = systemService;
            this.typedFactory = typedFactory;
        }

        public async System.Threading.Tasks.Task<IsDatabaseAliveResult> QueryIfDatabaseIsAlive()
        {
            var processRunner = typedFactory.Create<ProcessRunner<IsDatabaseAliveResult>>();

            var result = await processRunner.Run(() => this.systemService.IsDatabaseAlive(), SpinnerText, SpinnerText);
            return result;
        }

        private string SpinnerText
        {
            get { return Valg.EVA.Skanning.Resources.Language.ScanLanguageString.DatabaseIsDownSolutionSpinnerText; }
        }
    }
}
