using adas_core.Domain.Enums;
using adas_core.Domain.Models.MongoModels;
using adas_core.Infrastructure.Utils.MongoMaps.Interfaz;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
namespace adas_core.Infrastructure.Utils.MongoMaps;
///
/// Represents a contributor that supplies entity map configuration related to display home functionality.
///
public class DisplayHomeConfigContributor : IEntityMapContributor
{
///
/// Registers BSON class maps for and types if they are not already registered, configuring MongoDB serialization with custom element names, default values, null-ignore behavior, and string-based enum serialization.
///
public void RegisterMaps()
{
if (!BsonClassMap.IsClassMapRegistered(typeof(CardConfig)))
BsonClassMap.RegisterClassMap(cm =>
{
cm.AutoMap();
cm.MapIdMember(c => c.Id).SetElementName("_id");
cm.MapMember(c => c.Rows).SetDefaultValue(new List());
});
if (!BsonClassMap.IsClassMapRegistered(typeof(RowCardConfig)))
BsonClassMap.RegisterClassMap(cm =>
{
cm.AutoMap();
cm.MapMember(c => c.Cells).SetDefaultValue(new List| ());
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1);
cm.MapMember(c => c.Border).SetIgnoreIfNull(true);
cm.MapMember(c => c.BorderRadius).SetIgnoreIfNull(true);
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
cm.MapMember(c => c.Size).SetIgnoreIfNull(true);
cm.MapMember(c => c.MarginTop).SetIgnoreIfNull(true);
cm.MapMember(c => c.MarginBottom).SetIgnoreIfNull(true);
cm.MapMember(c => c.MarginLeft).SetIgnoreIfNull(true);
cm.MapMember(c => c.MarginRight).SetIgnoreIfNull(true);
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
cm.MapMember(c => c.Type)
.SetDefaultValue(DisplayConfigEnums.CellType.Default)
.SetSerializer(new EnumSerializer(BsonType.String));
});
}
} |