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

namespace Valg.EVA.Skanning.Configuration
{
    public class ReadSoftConfiguration : IReadSoftConfiguration
    {
        private readonly Dictionary<string, string> iniSettings;

        public ReadSoftConfiguration(IApplicationConfigurationReader applicationConfigurationReader)
        {
            JobPackageName = applicationConfigurationReader.GetAppSetting("JobPackageName");
            ScanningDataTempLocation = applicationConfigurationReader.GetAppSetting("ReadSoft.ScanningDataTempLocation");
            iniSettings = applicationConfigurationReader.GetAppSettingsStartsWith("ReadSoft.INI");
            InterpretInParallel = bool.Parse(applicationConfigurationReader.GetAppSetting("InterpretInParallel"));
            StateReportConnectionString = applicationConfigurationReader.GetAppSetting("StateReportConnectionString");
        }

        public void TransformAppSettingsToIniConfiguration()
        {
            foreach (var iniSetting in iniSettings)
            {
                new ReadSoftIniKey(iniSetting.Key).SetValue(iniSetting.Value);
            }
        }

        public string GetIniConfigurationValue(string key)
        {
            return new ReadSoftIniKey(key).IniValue;
        }

        public string ScanningDataTempLocation { get; }
        public string JobPackageName { get; }
        public bool InterpretInParallel { get; }
        public string StateReportConnectionString { get; }

        public static ReadSoftConfiguration GetDefaultReadSoftConfiguration()
        {
            return new ReadSoftConfiguration(new ApplicationConfigurationReader(new ConfigurationFileProvider("Valg.EVA.Skanning.Scan.Presentation.dll.config")));
        }
    }
}
