
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using audit_logs.Models.AppSettings;
using audit_logs.Repositories;
using audit.Repositories;
using audit_logs.Repositories.Interfaces;
using audit_logs.Services;
using audit_logs.Services.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using MongoDB.Driver;

namespace audit_logs.Extensions;

public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddAuditServices(this IServiceCollection services, IConfiguration configuration)
    {
        // Configurar MongoDbSettingsAudit a partir del archivo de configuración appsettings.json
        services.Configure<MongoDbSettingsAudit>(configuration.GetSection("DatabaseConfigurationAudit"));

        // Registrar AuditService utilizando la configuración de MongoDbSettingsAudit
        services.AddScoped<IAuditService, AuditService>(sp =>
        {
            var options = sp.GetRequiredService<IOptions<MongoDbSettingsAudit>>();
            return new AuditService(options);
        });
        services.AddScoped<IDeepCopyService, DeepCopyService>();

        return services;
    }
}