using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SIGCM.Domain.Interfaces;
using SIGCM.Application.Interfaces;
using SIGCM.Infrastructure.Data;
using SIGCM.Infrastructure.Repositories;
using SIGCM.Infrastructure.Services;

namespace SIGCM.Infrastructure;

public static class DependencyInjection
{
    public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddSingleton<IDbConnectionFactory, DbConnectionFactory>();
        services.AddSingleton<DbInitializer>();
        services.AddScoped<ICategoryRepository, CategoryRepository>();
        services.AddScoped<IOperationRepository, OperationRepository>();
        services.AddScoped<IUserRepository, UserRepository>();
        services.AddScoped<ITokenService, TokenService>();
        services.AddScoped<IAuthService, AuthService>();
        services.AddScoped<IAttributeDefinitionRepository, AttributeDefinitionRepository>();
        services.AddScoped<IListingRepository, ListingRepository>();
        services.AddScoped<IImageRepository, ImageRepository>();
        services.AddScoped<PricingRepository>();
        services.AddScoped<PricingService>();
        services.AddScoped<ClientRepository>();
        services.AddScoped<AuditRepository>();
        //services.AddScoped<CashClosingRepository>();
        services.AddScoped<CashSessionRepository>(); 
        services.AddScoped<EditionClosureRepository>();
        services.AddScoped<ImageOptimizationService>();
        services.AddScoped<IClaimRepository, ClaimRepository>();
        services.AddScoped<NotificationRepository>();
        services.AddScoped<ICouponRepository, CouponRepository>();
        services.AddScoped<IListingNoteRepository, ListingNoteRepository>();

        // Registro de MercadoPagoService configurado desde IConfiguration (appsettings o env vars)
        services.AddScoped<MercadoPagoService>(sp =>
        {
            return new MercadoPagoService(
                configuration["MercadoPago:AccessToken"] ?? "TEST-YOUR-TOKEN",
                configuration["MercadoPago:SuccessUrl"] ?? "http://localhost:5173/publicar/exito",
                configuration["MercadoPago:FailureUrl"] ?? "http://localhost:5173/publicar/error",
                configuration["MercadoPago:NotificationUrl"] ?? "https://yourdomain.com/api/payments/webhook"
            );
        });

        return services;
    }
}





