using adas_core.Domain.Enums;
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;

namespace adas_core.Infrastructure.Utils.MongoMaps;

public class BannerConfigMapContributor : IEntityMapContributor
{
    public void RegisterMaps()
    {
        if (!BsonClassMap.IsClassMapRegistered(typeof(BannerItem)))
            BsonClassMap.RegisterClassMap<BannerItem>(cm =>
            {
                cm.AutoMap();
                cm.MapMember(c => c.Type)
                    .SetIgnoreIfNull(true)
                    .SetSerializer(
                        new NullableSerializer<DisplayConfigEnums.BannerType>(
                            new EnumSerializer<DisplayConfigEnums.BannerType>(BsonType.String)));
                cm.MapMember(c => c.GrowPriority).SetDefaultValue(1);
                cm.MapMember(c => c.Config).SetIgnoreIfNull(true);
            });

        if (!BsonClassMap.IsClassMapRegistered(typeof(BannerItemConfig)))
            BsonClassMap.RegisterClassMap<BannerItemConfig>(cm =>
            {
                cm.AutoMap();
                cm.MapMember(c => c.BannerItemDialogTableConfig).SetIgnoreIfNull(true);
                cm.MapMember(c => c.BannerItemTableConfig).SetIgnoreIfNull(true);
                cm.MapMember(c => c.MedicalStaffConfig).SetIgnoreIfNull(true);
            });

        if (!BsonClassMap.IsClassMapRegistered(typeof(BannerItemTableConfig)))
            BsonClassMap.RegisterClassMap<BannerItemTableConfig>(cm =>
            {
                cm.AutoMap();
                cm.MapMember(c => c.Config).SetIgnoreIfNull(true);
                cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
                cm.MapMember(c => c.TextColor).SetIgnoreIfNull(true);
            });

        if (!BsonClassMap.IsClassMapRegistered(typeof(HeaderBannerItemTableConfig)))
            BsonClassMap.RegisterClassMap<HeaderBannerItemTableConfig>(cm =>
            {
                cm.MapMember(c => c.Type)
                    .SetIgnoreIfNull(true)
                    .SetSerializer(
                        new NullableSerializer<DisplayConfigEnums.CellType>(
                            new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String)));
                cm.MapMember(c => c.SubType).SetIgnoreIfNull(true);
                cm.MapMember(c => c.Field).SetIgnoreIfNull(true);
                cm.MapMember(c => c.GrowPriority).SetIgnoreIfNull(true);
                cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
                cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
                cm.MapMember(c => c.TextColor).SetIgnoreIfNull(true);
                cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
            });
    }
}