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;

public class CameraContributor : IEntityMapContributor
{
    public void RegisterMaps()
    {
        if (!BsonClassMap.IsClassMapRegistered(typeof(Camera)))
        {
            BsonClassMap.RegisterClassMap<Camera>(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<Domain.Models.MongoModels.Stream>(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);
            });
        }
    }
}