using DigitalData.Core.Application.Interfaces.Repository;
using Microsoft.Extensions.DependencyInjection;

namespace DigitalData.Core.Infrastructure;

public class EntityConfigurationOptions<TEntity>
{
    private readonly IServiceCollection _services;

    public EntityConfigurationOptions(IServiceCollection services)
    {
        _services = services;
    }

    public EntityConfigurationOptions<TEntity> AddCustomMapper<TEntityMapper>(Action<IServiceCollection> configure, Func<IServiceProvider, TEntityMapper>? factory = null)
        where TEntityMapper : class, IEntityMapper<TEntity>
    {
        configure(_services);

        if (factory is null)
            _services.AddSingleton<IEntityMapper<TEntity>, TEntityMapper>();
        else
            _services.AddSingleton(factory);
        
        return this;
    }
}
