using System;
using Valg.EVA.Skanning.Contracts;

namespace Valg.EVA.Skanning.Configuration
{
    public class ExternalEndpointsConfiguration : IExternalEndpointsConfiguration
    {
        public ExternalEndpointsConfiguration(IApplicationConfigurationReader applicationConfigurationReader)
        {
            LogonStartUrl = applicationConfigurationReader.GetAppSetting("LogonStartUrl");
            LogonCompleteUrl = applicationConfigurationReader.GetAppSetting("LogonCompleteUrl");
            HelpMappingUrl = applicationConfigurationReader.GetAppSetting("HelpMappingUrl");
            TransferWebServiceUrl = applicationConfigurationReader.GetTransferWebServiceUrl();

            var statusCheckExpirationInMinutes = applicationConfigurationReader.GetOptionalAppSetting("StatusCheckExpirationInMinutes");
            if (!string.IsNullOrEmpty(statusCheckExpirationInMinutes))
            {
                StatusCheckExpirationInMinutes = Convert.ToInt32(applicationConfigurationReader.GetOptionalAppSetting("StatusCheckExpirationInMinutes"));
            }

            var statusCheckEveryXSeconds = applicationConfigurationReader.GetOptionalAppSetting("StatusCheckEveryXSeconds");
            StatusCheckEveryXSeconds = !string.IsNullOrEmpty(statusCheckEveryXSeconds) ? Convert.ToInt32(statusCheckEveryXSeconds) : 8;
        }

        public string LogonStartUrl { get; }
        public string LogonCompleteUrl { get; }
        public string HelpMappingUrl { get; }
        public int StatusCheckExpirationInMinutes { get; }
        public string TransferWebServiceUrl { get; }
        public int StatusCheckEveryXSeconds { get; }
    }
}
