using System.Data.SqlClient;
using UI.Configuracao;

namespace UI.Database
{
    public class DatabaseService
    {
        public static SqlConnection GetConnection()
        {
            var cfg = DatabaseConfig.Load();

            string connectionString;

            if (cfg.Integrada)
            {
                connectionString =
                    $"Server={cfg.Servidor};Database={cfg.Banco};Trusted_Connection=True;TrustServerCertificate=True;";
            }
            else
            {
                connectionString =
                    $"Server={cfg.Servidor};Database={cfg.Banco};User Id={cfg.Usuario};Password={cfg.Senha};TrustServerCertificate=True;";
            }

            return new SqlConnection(connectionString);
        }
    }
}