using Dapper; using GestionIntegral.Api.Models.Suscripciones; namespace GestionIntegral.Api.Data.Repositories.Suscripciones { public class FormaPagoRepository : IFormaPagoRepository { private readonly DbConnectionFactory _connectionFactory; private readonly ILogger _logger; public FormaPagoRepository(DbConnectionFactory connectionFactory, ILogger logger) { _connectionFactory = connectionFactory; _logger = logger; } public async Task> GetAllAsync() { const string sql = @" SELECT IdFormaPago, Nombre, RequiereCBU, Activo FROM dbo.susc_FormasDePago WHERE Activo = 1 ORDER BY Nombre;"; try { using var connection = _connectionFactory.CreateConnection(); return await connection.QueryAsync(sql); } catch (Exception ex) { _logger.LogError(ex, "Error al obtener todas las Formas de Pago activas."); return Enumerable.Empty(); } } public async Task GetByIdAsync(int id) { const string sql = @" SELECT IdFormaPago, Nombre, RequiereCBU, Activo FROM dbo.susc_FormasDePago WHERE IdFormaPago = @Id;"; try { using var connection = _connectionFactory.CreateConnection(); return await connection.QuerySingleOrDefaultAsync(sql, new { Id = id }); } catch (Exception ex) { _logger.LogError(ex, "Error al obtener Forma de Pago por ID: {IdFormaPago}", id); return null; } } } }