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

namespace Valg.EVA.Skanning.Entity.SqlConnection
{
    public class SqlConnectionFactory : ISqlConnectionFactory
    {
        private readonly IDatabaseConfiguration databaseConfiguration;

        public SqlConnectionFactory(IDatabaseConfiguration databaseConfiguration)
        {
            this.databaseConfiguration = databaseConfiguration;
        }

        public System.Data.SqlClient.SqlConnection CreateSqlConnection()
        {
            return new System.Data.SqlClient.SqlConnection(databaseConfiguration.ConnectionString);
        }

        public int? GetCommandTimeOut(int? defaultTimeOut)
        {
            if (databaseConfiguration.OverrideTimeOut)
            { 
                return databaseConfiguration.CommandTimeOut;  
            }

            return defaultTimeOut;
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
        public SqlCommand CreateSqlCommand(string sqlCommand, System.Data.SqlClient.SqlConnection connection)
        {
            return new SqlCommand(sqlCommand, connection);
        }
    }
}

