using adas_core.Domain.Models.MongoModels; using adas_core.Infrastructure.Utils.MongoMaps.Interfaz; using MongoDB.Bson.Serialization; namespace adas_core.Infrastructure.Utils.MongoMaps; /// /// Represents a contributor that participates in entity mapping, providing header-related mapping logic. /// /// /// Implements the interface to contribute mapping behavior within the entity mapping pipeline. /// public class HeaderMapContributor : IEntityMapContributor { /// /// Registers BSON class maps for the type and its nested type with the MongoDB BsonClassMap serializer, configuring default values and null-ignore behavior for their members. Registration is performed only if a class map for the corresponding type has not already been registered, preventing duplicate registrations. /// public void RegisterMaps() { if (!BsonClassMap.IsClassMapRegistered(typeof(HeaderConfig))) BsonClassMap.RegisterClassMap(cm => { cm.AutoMap(); cm.MapMember(c => c.PartnerLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.CompanyLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.CenterLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.MeddisLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.UnitName).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.Cameras).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.Sensors).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.Fullscreen).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.Sounds).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.Sidebar).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); cm.MapMember(c => c.CurrentDateTime).SetDefaultValue(new HeaderConfig.HeaderItem()) .SetIgnoreIfNull(true); cm.MapMember(c => c.SectionTitle).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true); }); if (!BsonClassMap.IsClassMapRegistered(typeof(HeaderConfig.HeaderItem))) BsonClassMap.RegisterClassMap(cm => { cm.AutoMap(); cm.MapMember(c => c.LogoUrl).SetDefaultValue(() => null) .SetIgnoreIfNull(true); cm.MapMember(c => c.IsVisible).SetDefaultValue(true); }); } }