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

namespace Valg.EVA.Skanning.Configuration
{
    public class DatabaseConfiguration : IDatabaseConfiguration
    {
        public DatabaseConfiguration(IApplicationConfigurationReader applicationConfigurationReader)
        {
            ConnectionString = applicationConfigurationReader.GetConnectionString();

            var internalConnectionStringBuilder = new SqlConnectionStringBuilder(ConnectionString);
            DatabaseServerName = internalConnectionStringBuilder.DataSource;

            DatabaseVersion =  applicationConfigurationReader.GetAppSetting("DatabaseVersion");
            OverrideTimeOut = Convert.ToBoolean(applicationConfigurationReader.GetAppSetting("OverrideTimeOut"));
            CommandTimeOut = Convert.ToInt32(applicationConfigurationReader.GetAppSetting("CommandTimeOut"));
            TransactionTimeOut = Convert.ToInt32(applicationConfigurationReader.GetAppSetting("TransactionTimeOut"));
        }

        public string ConnectionString { get; }
        public string DatabaseServerName { get; }
        public string DatabaseVersion { get; }
        public bool OverrideTimeOut { get; }
        public int TransactionTimeOut { get; }
        public int CommandTimeOut { get; }
    }
}
