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

namespace Valg.EVA.Skanning.Configuration
{
    public class DiagnosticsConfiguration : IDiagnosticsConfiguration
    {
        public DiagnosticsConfiguration(IApplicationConfigurationReader applicationConfigurationReader)
        {
            
            IsPerformanceMeasurementProbeEnabled = Convert.ToBoolean(applicationConfigurationReader.GetAppSetting("Diagnostics.IsPerformanceMeasurementProbeEnabled"));
            LogDirectory = applicationConfigurationReader.GetAppSetting("Diagnostics.LogDirectory");
            IsInProcessFileLoggingSinkEnabled = Convert.ToBoolean(applicationConfigurationReader.GetAppSetting("Diagnostics.IsInProcessFileLoggingSinkEnabled"));
            IsGenerateBarcodeUtilityEnabled = GetIsGenerateBarcodeButtonEnabled(applicationConfigurationReader);
        }

        private bool GetIsGenerateBarcodeButtonEnabled(IApplicationConfigurationReader applicationConfigurationReader)
        {
            bool result;
            var appSetting = applicationConfigurationReader.GetOptionalAppSetting("Diagnostics.IsGenerateBarcodeUtilityEnabled");
            bool.TryParse(appSetting, out result);
            return result;
        }

        public string LogDirectory { get; }
        public bool IsPerformanceMeasurementProbeEnabled { get; }
        public bool IsInProcessFileLoggingSinkEnabled { get; }
        public bool IsGenerateBarcodeUtilityEnabled { get; }
    }
}
