using adas_core.Domain.Models.MongoModels;
using adas_core.Infrastructure.Utils.MongoMaps.Interfaz;
using MongoDB.Bson.Serialization;

namespace adas_core.Infrastructure.Utils.MongoMaps;

/// <summary>
/// Represents a contributor that supplies color configuration mappings for entities
/// by implementing the <see cref="IEntityMapContributor"/> interface.
/// </summary>
/// <remarks>
/// Used as a pluggable component within the entity mapping pipeline to apply
/// color-related configuration to mapped entities.
/// </remarks>
public class ColorConfigMapContributor : IEntityMapContributor
{
    /// <summary>
    /// Registers BSON class maps for the <see cref="ColorConfig"/> type and its nested configuration types, providing default color and appearance values for properties such as levels, text, arrows, indicators, graphs, status boxes, therapy, tests, and procedures. Each class map is registered only if it has not already been registered, ensuring idempotent initialization of the MongoDB serialization mappings used by the color configuration system.
    /// </summary>
    public void RegisterMaps()
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig)))
                BsonClassMap.RegisterClassMap<ColorConfig>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Level).SetDefaultValue(new ColorConfig.LevelColors
                    {
                        Level1 = "#FFFFFF",
                        Level2 = "#FAFF41",
                        Level3 = "#F5A623",
                        Level4 = "#C2510F",
                        Level5 = "#FF5D6A"
                    }).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.Text).SetDefaultValue(new ColorConfig.TextColors
                    {
                        Normal = "#FFFFFF",
                        Warning = "#FFAD26",
                        Alert = "#FF5D6A",
                        Improve = "#60D61D",
                        Expired = "#333333"
                    }).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.Arrow).SetDefaultValue(new ColorConfig.ArrowColors
                    {
                        Normal = "#FFFFFF",
                        Warning = "#F5A623",
                        Alert = "#FF5D6A",
                        Improve = "#60D61D"
                    }).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.Indicator).SetDefaultValue(new ColorConfig.IndicatorColors
                    {
                        Empty = "#CCCCCC",
                        Warning = "#FFAD26",
                        Normal = "#60D61D",
                        Alert = "#FF5D6A",
                        Background = "#000000",
                        EmptyBackground = "#CCCCCC"
                    }).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.Graph).SetDefaultValue(new ColorConfig.GraphColors
                    {
                        Alert = "#FF5D6A",
                        Warning = "#FFAD26",
                        Normal = "#60D61D"
                    }).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.BoxNumber).SetDefaultValue(new ColorConfig.StatusBoxNumberColors
                    {
                        Reserved =
                            new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        InUse = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Available = new ColorConfig.AppearanceSettings
                            { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Locked = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Transferable = new ColorConfig.AppearanceSettings
                            { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Exitus = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Altable = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" }
                    }).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.BoxStatusColor).SetDefaultValue(new ColorConfig.StatusBoxNumberColors
                    {
                        Reserved =
                            new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        InUse = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Available = new ColorConfig.AppearanceSettings
                            { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Locked = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Transferable = new ColorConfig.AppearanceSettings
                            { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Exitus = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
                        Altable = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" }
                    }).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.Therapy).SetDefaultValue(new ColorConfig.TherapyColors
                    {
                        Default = new ColorConfig.AppearanceSettings(),
                        Finished = new ColorConfig.AppearanceSettings(),
                        Initialized = new ColorConfig.AppearanceSettings(),
                        InProgress = new ColorConfig.AppearanceSettings()
                    }).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.Test).SetDefaultValue(new ColorConfig.TestColors
                    {
                        Default = new ColorConfig.AppearanceSettings
                        {
                            BackgroundColor = "#00A4E1",
                            TextColor = "#FFF"
                        },
                        Finished = new ColorConfig.AppearanceSettings
                        {
                            BackgroundColor = "#00C49B",
                            TextColor = "#FFF",
                            Icon = "assets/icon/light-theme/ic-tick.svg",
                            IconDefault = "icTick"
                        },
                        Initialized = new ColorConfig.AppearanceSettings
                        {
                            BackgroundColor = "#ED4965",
                            TextColor = "#FFF"
                        },
                        Expired = new ColorConfig.AppearanceSettings
                        {
                            BackgroundColor = "#ED4965",
                            TextColor = "#FFF",
                            Icon = "assets/icon/light-theme/ic-clock.svg",
                            IconDefault = "icClock"
                        }
                    }).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.Procedure).SetDefaultValue(new ColorConfig.ProcedureColors
                    {
                        Default = new ColorConfig.AppearanceSettings
                        {
                            BackgroundColor = "#00A4E1",
                            TextColor = "#FFF"
                        },
                        Finished = new ColorConfig.AppearanceSettings
                        {
                            BackgroundColor = "#00C49B",
                            TextColor = "#FFF",
                            Icon = "assets/icon/light-theme/ic-tick.svg",
                            IconDefault = "icTick"
                        },
                        Initialized = new ColorConfig.AppearanceSettings
                        {
                            BackgroundColor = "#ED4965",
                            TextColor = "#FFF"
                        },
                        Expired = new ColorConfig.AppearanceSettings
                        {
                            BackgroundColor = "#ED4965",
                            TextColor = "#FFF",
                            Icon = "assets/icon/light-theme/ic-clock.svg",
                            IconDefault = "icClock"
                        }
                    }).SetIgnoreIfNull(true);
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.StatusBoxNumberColors)))
                BsonClassMap.RegisterClassMap<ColorConfig.StatusBoxNumberColors>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Reserved).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#FFF84C",
                        TextColor = "#000000"
                    });
                    cm.MapMember(c => c.InUse).SetDefaultValue(new ColorConfig.AppearanceSettings());
                    cm.MapMember(c => c.Available).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#57B812",
                        TextColor = "#000000"
                    });
                    cm.MapMember(c => c.Locked).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#ED4965",
                        TextColor = "#000000"
                    });
                    cm.MapMember(c => c.Transferable).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#57B812",
                        TextColor = "#000000"
                    });
                    cm.MapMember(c => c.Exitus).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#24BFF9",
                        TextColor = "#000000"
                    });
                    cm.MapMember(c => c.Altable).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#24BFF9",
                        TextColor = "#000000"
                    });
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.TherapyColors)))
                BsonClassMap.RegisterClassMap<ColorConfig.TherapyColors>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Default).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#00A4E1",
                        TextColor = "#FFF",
                        IconInvertColor = 1
                    });
                    cm.MapMember(c => c.Initialized).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#FFF",
                        TextColor = "#000"
                    });
                    cm.MapMember(c => c.Finished).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#FFF",
                        TextColor = "#000",
                        Icon = "assets/icon/light-theme/ic-tick.svg",
                        IconDefault = "icTick"
                    });
                    cm.MapMember(c => c.InProgress).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#FFF",
                        TextColor = "#000"
                    });
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.AppearanceSettings)))
                BsonClassMap.RegisterClassMap<ColorConfig.AppearanceSettings>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.TextColor).SetDefaultValue("#000000");
                    cm.MapMember(c => c.BackgroundColor).SetDefaultValue("#FFFFFF");
                    cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.IconDefault).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.IconColor).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.IconCategory).SetIgnoreIfNull(true);
                    cm.MapMember(c => c.IconInvertColor).SetDefaultValue(0.0);
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.TestColors)))
                BsonClassMap.RegisterClassMap<ColorConfig.TestColors>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Default).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#00A4E1",
                        TextColor = "#FFF"
                    });
                    cm.MapMember(c => c.Initialized).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#ED4965",
                        TextColor = "#FFF"
                    });
                    cm.MapMember(c => c.Finished).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#00C49B",
                        TextColor = "#FFF",
                        Icon = "assets/icon/light-theme/ic-tick.svg",
                        IconDefault = "icTick"
                    });
                    cm.MapMember(c => c.Expired).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#ED4965",
                        TextColor = "#FFF",
                        Icon = "assets/icon/light-theme/ic-clock.svg",
                        IconDefault = "icClock"
                    });
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.ProcedureColors)))
                BsonClassMap.RegisterClassMap<ColorConfig.ProcedureColors>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Default).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#00A4E1",
                        TextColor = "#FFF"
                    });
                    cm.MapMember(c => c.Initialized).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#ED4965",
                        TextColor = "#FFF"
                    });
                    cm.MapMember(c => c.Finished).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#00C49B",
                        TextColor = "#FFF",
                        Icon = "assets/icon/light-theme/ic-tick.svg",
                        IconDefault = "icTick"
                    });
                    cm.MapMember(c => c.Expired).SetDefaultValue(new ColorConfig.AppearanceSettings
                    {
                        BackgroundColor = "#ED4965",
                        TextColor = "#FFF",
                        Icon = "assets/icon/light-theme/ic-clock.svg",
                        IconDefault = "icClock"
                    });
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.LevelColors)))
                BsonClassMap.RegisterClassMap<ColorConfig.LevelColors>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Level1).SetDefaultValue("#FFFFFF");
                    cm.MapMember(c => c.Level2).SetDefaultValue("#FAFF41");
                    cm.MapMember(c => c.Level3).SetDefaultValue("#F5A623");
                    cm.MapMember(c => c.Level4).SetDefaultValue("#C2510F");
                    cm.MapMember(c => c.Level5).SetDefaultValue("#FF5D6A");
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.TextColors)))
                BsonClassMap.RegisterClassMap<ColorConfig.TextColors>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Normal).SetDefaultValue("#FFFFFF");
                    cm.MapMember(c => c.Warning).SetDefaultValue("#FFAD26");
                    cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
                    cm.MapMember(c => c.Improve).SetDefaultValue("#60D61D");
                    cm.MapMember(c => c.Expired).SetDefaultValue("#333333");
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.ArrowColors)))
                BsonClassMap.RegisterClassMap<ColorConfig.ArrowColors>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Normal).SetDefaultValue("#FFFFFF");
                    cm.MapMember(c => c.Warning).SetDefaultValue("#F5A623");
                    cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
                    cm.MapMember(c => c.Improve).SetDefaultValue("#60D61D");
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.IndicatorColors)))
                BsonClassMap.RegisterClassMap<ColorConfig.IndicatorColors>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Empty).SetDefaultValue("#CCCCCC");
                    cm.MapMember(c => c.Warning).SetDefaultValue("#FFAD26");
                    cm.MapMember(c => c.Normal).SetDefaultValue("#60D61D");
                    cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
                    cm.MapMember(c => c.Background).SetDefaultValue("#000000");
                    cm.MapMember(c => c.EmptyBackground).SetDefaultValue("#CCCCCC");
                });
    
            if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.GraphColors)))
                BsonClassMap.RegisterClassMap<ColorConfig.GraphColors>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(c => c.Normal).SetDefaultValue("#60D61D");
                    cm.MapMember(c => c.Warning).SetDefaultValue("#FFAD26");
                    cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
                });
        }
}