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

namespace adas_core.Infrastructure.Utils.MongoMaps;

public class ServiceConfigMapContributor : IEntityMapContributor
{
    public void RegisterMaps()
    {
        if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfig)))
            BsonClassMap.RegisterClassMap<ServiceConfig>(cm =>
            {
                cm.AutoMap();
                cm.MapIdMember(c => c.Id).SetElementName("_id");
                cm.MapMember(c => c.StrId).SetElementName("id")
                    .SetDefaultValue(string.Empty);
                cm.MapMember(c => c.Service).SetDefaultValue(new List<ServiceConfigService>());
                cm.MapMember(c => c.Theme).SetIgnoreIfNull(true);
                cm.MapMember(c => c.BoxObservations).SetIgnoreIfNull(true);
                cm.MapMember(c => c.Score).SetDefaultValue(string.Empty);
            });

        if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigService)))
            BsonClassMap.RegisterClassMap<ServiceConfigService>(cm =>
            {
                cm.AutoMap();
                cm.MapMember(c => c.Screen).SetDefaultValue(string.Empty);
                cm.MapMember(c => c.Sections).SetDefaultValue(new List<ServiceConfigServiceSection>());
            });

        if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigServiceSection)))
            BsonClassMap.RegisterClassMap<ServiceConfigServiceSection>(cm =>
            {
                cm.AutoMap();
                cm.MapMember(c => c.BoxId).SetDefaultValue(string.Empty);
                cm.MapMember(c => c.Box).SetDefaultValue(string.Empty);
            });

        if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigTheme)))
            BsonClassMap.RegisterClassMap<ServiceConfigTheme>(cm =>
            {
                cm.AutoMap();
                cm.MapMember(c => c.DefaultTheme).SetElementName("default")
                    .SetDefaultValue(string.Empty);
                cm.MapMember(c => c.Timetables).SetDefaultValue(new List<ServiceConfigThemeTimetable>());
            });

        if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigThemeTimetable)))
            BsonClassMap.RegisterClassMap<ServiceConfigThemeTimetable>(cm =>
            {
                cm.AutoMap();
                cm.MapMember(c => c.Theme).SetDefaultValue(string.Empty);
                cm.MapMember(c => c.StartDay).SetDefaultValue(string.Empty);
                cm.MapMember(c => c.EndDay).SetDefaultValue(string.Empty);
                cm.MapMember(c => c.StartHour).SetDefaultValue(string.Empty);
                cm.MapMember(c => c.EndHour).SetDefaultValue(string.Empty);
            });
    }
}