using adas_core.Domain.Models.MongoModels;
using adas_core.Infrastructure.Utils.MongoMaps.Interfaz;
using adas_core.module.LightBeacons.Devices;
using MongoDB.Bson.Serialization;
using LightBeacon = adas_core.Domain.Models.MongoModels.LightBeacon;
namespace adas_core.Infrastructure.Utils.MongoMaps;
///
/// Represents a map contributor that participates in entity mapping operations
/// for beacon-related entities.
///
///
/// Implements the interface to contribute
/// beacon-specific mapping logic.
///
public class BeaconMapContributor : IEntityMapContributor
{
///
/// Registers BSON class maps for , , and types to configure their MongoDB serialization. Each registration is skipped if a class map for the type has already been registered, applying default values, element name mappings, and ignore-if-null settings to the respective members.
///
public void RegisterMaps()
{
if (!BsonClassMap.IsClassMapRegistered(typeof(LightBeacon)))
BsonClassMap.RegisterClassMap(cm =>
{
cm.AutoMap();
cm.MapIdMember(c => c.Id).SetElementName("_id");
cm.MapMember(c => c.Type).SetDefaultValue(string.Empty);
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
cm.MapMember(c => c.Options).SetDefaultValue(new Options());
cm.MapMember(c => c.InUse).SetIgnoreIfNull(true).SetIsRequired(false);
});
if (!BsonClassMap.IsClassMapRegistered(typeof(Options)))
BsonClassMap.RegisterClassMap(cm =>
{
cm.AutoMap();
cm.MapMember(c => c.Url).SetIgnoreIfNull(true);
cm.MapMember(c => c.Port).SetIgnoreIfNull(true);
cm.MapMember(c => c.Password).SetIgnoreIfNull(true);
cm.MapMember(c => c.Emulate).SetDefaultValue(false);
});
if (!BsonClassMap.IsClassMapRegistered(typeof(LightBeaconAbstract)))
BsonClassMap.RegisterClassMap(cm =>
{
cm.AutoMap();
cm.MapMember(c => c.Host);
cm.MapMember(c => c.Password);
});
}
}