namespace TaxBaik.Infrastructure.Data;

using System.Data;
using Microsoft.Extensions.Configuration;
using Npgsql;
using Dapper;
using TaxBaik.Domain.Interfaces;

public sealed class DbConnectionFactory : IDbConnectionFactory
{
    static DbConnectionFactory()
    {
        // Keep PostgreSQL snake_case columns aligned with C# PascalCase properties.
        DefaultTypeMap.MatchNamesWithUnderscores = true;
    }

    private readonly string _connectionString;

    public DbConnectionFactory(IConfiguration configuration)
    {
        _connectionString = configuration.GetConnectionString("Default")
            ?? throw new InvalidOperationException("Missing 'Default' connection string in configuration.");
    }

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