using System.Data;
using Microsoft.Data.SqlClient;

namespace PlotLine.Data;

public interface ISqlConnectionFactory
{
    IDbConnection CreateConnection();
}

public sealed class SqlConnectionFactory(IConfiguration configuration) : ISqlConnectionFactory
{
    private readonly string _connectionString = configuration.GetConnectionString("DefaultConnection")
        ?? throw new InvalidOperationException("DefaultConnection is not configured.");

    public IDbConnection CreateConnection() => new SqlConnection(_connectionString);
}
