using Microsoft.EntityFrameworkCore;

namespace Lada.Framework.Data.Mappings
{
    public static class EntityMappingExtensions
    {
        public static ModelBuilder RegisterEntityMapping<TEntity, TMapping>(this ModelBuilder builder)
            where TMapping : IEntityMappingConfiguration<TEntity>
            where TEntity : class
        {
            IEntityMappingConfiguration<TEntity>? mapper = Activator.CreateInstance(typeof(TMapping)) as IEntityMappingConfiguration<TEntity>;
            mapper.Map(builder.Entity<TEntity>());
            return builder;
        }
    }
}
