using adas_core.Domain.Models.MongoModels;
using adas_core.Infrastructure.Utils.MongoMaps.Interfaz;
using MongoDB.Bson.Serialization;
using Stream = System.IO.Stream;
namespace adas_core.Infrastructure.Utils.MongoMaps;
///
/// Represents a contributor that participates in entity mapping operations related to camera entities.
///
///
/// Implements the interface to provide camera-specific mapping behavior within the entity mapping pipeline.
///
public class CameraContributor : IEntityMapContributor
{
///
/// Registers BSON class maps for the and types with MongoDB, applying custom mapping conventions such as element name overrides, default values, and ignore-if-null behavior. Registration is performed only once; the method guards against duplicate registration by checking before registering.
///
public void RegisterMaps()
{
if (!BsonClassMap.IsClassMapRegistered(typeof(Camera)))
{
BsonClassMap.RegisterClassMap(cm =>
{
cm.AutoMap();
cm.MapIdMember(c => c.Id).SetElementName("_id");
cm.MapMember(c => c.Streams).SetIgnoreIfNull(true);
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
cm.MapMember(c => c.Ptz).SetDefaultValue(false);
cm.MapMember(c => c.Driver).SetIgnoreIfNull(true);
cm.MapMember(c => c.Ip).SetIgnoreIfNull(true);
cm.MapMember(c => c.Username).SetIgnoreIfNull(true);
cm.MapMember(c => c.Password).SetIgnoreIfNull(true);
cm.MapMember(c => c.InUse).SetIgnoreIfNull(true).SetIsRequired(false);
});
BsonClassMap.RegisterClassMap(cm =>
{
cm.AutoMap();
cm.MapMember(c => c.Rtsp).SetIgnoreIfNull(true);
cm.MapMember(c => c.Jpeg).SetIgnoreIfNull(true);
cm.MapMember(c => c.WebRtc).SetIgnoreIfNull(true);
cm.MapMember(c => c.Hls).SetIgnoreIfNull(true);
cm.MapMember(c => c.Mp4).SetIgnoreIfNull(true);
});
}
}
}