using adas_core.Domain.Enums;
using adas_core.Domain.Models.BsonConverters;
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;
using Stream = adas_core.Domain.Models.MongoModels.Stream;


namespace adas_core.Infrastructure.Utils.MongoMaps;

/// <summary>
/// Provides configuration mapping contributions for box entities, implementing the <see cref="IEntityMapContributor"/> interface to participate in entity map setup.
/// </summary>
public class BoxConfigMapContributor : IEntityMapContributor
{
    public void RegisterMaps()
    {
        if (!BsonClassMap.IsClassMapRegistered(typeof(Box)))
            BsonClassMap.RegisterClassMap<Box>(cm =>
            {
                cm.AutoMap();
                cm.UnmapMember(c => c.PointOfCare); //Esto hace que ignora la propiedad en la serialización del Bson
                cm.MapMember(c => c.Bed).SetElementName("name");
                cm.UnmapMember(c => c.IsActive);
                cm.UnmapMember(c => c.IsVisible);
                cm.MapMember(c => c.Configuration)
                    .SetSerializer(new DictionaryBsonConverter())
                    .SetIgnoreIfNull(true);
                cm.UnmapMember(c => c.Location);
                cm.UnmapMember(c => c.HasPatient);
                cm.UnmapMember(c => c.Patientid);
                cm.UnmapMember(c => c.Patient);
                cm.UnmapMember(c => c.AttendingDoctor);
                cm.UnmapMember(c => c.Type);
                cm.UnmapMember(c => c.Observations);
                cm.UnmapMember(c => c.Medication);
            });

        if (!BsonClassMap.IsClassMapRegistered(typeof(Sensor)))
            BsonClassMap.RegisterClassMap<Sensor>(cm =>
            {
                cm.AutoMap();
                cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
                cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
                cm.MapMember(c => c.OnlyNumbers).SetDefaultValue(true);
                cm.MapMember(c => c.IsGeneral).SetDefaultValue(true);
            });
    }
}