using Domain.Entities.Donations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure.Persistence.Configurations.Donations;

public class DonationAlertConfigConfiguration : IEntityTypeConfiguration<DonationAlertConfig>
{
    public void Configure(EntityTypeBuilder<DonationAlertConfig> builder)
    {
        builder.ToTable(nameof(DonationAlertConfig), x => x.HasComment("후원 알림 위젯 설정"));
        builder.HasKey(x => x.ID);

        builder.HasOne(x => x.Channel).WithMany().HasForeignKey(x => x.ChannelID).OnDelete(DeleteBehavior.Cascade);
        builder.HasOne(x => x.Member).WithMany().HasForeignKey(x => x.MemberID).OnDelete(DeleteBehavior.NoAction);

        builder.HasIndex(x => new { x.ChannelID, x.MemberID, x.Amount });
        builder.HasIndex(x => new { x.ChannelID, x.IsActive });
        builder.HasIndex(x => new { x.ChannelID, x.MatchType, x.Amount });

        builder.Property(x => x.Title).HasMaxLength(200).IsRequired();
        builder.Property(x => x.Message).HasMaxLength(200).IsRequired();

        builder.Property(x => x.PopupEffect).HasMaxLength(50);
        builder.Property(x => x.TextEffect).HasMaxLength(50);

        builder.Property(x => x.NicknameFontFamily).HasMaxLength(100);
        builder.Property(x => x.NicknameFontColor).HasMaxLength(20).IsRequired();
        builder.Property(x => x.AmountFontFamily).HasMaxLength(100);
        builder.Property(x => x.AmountFontColor).HasMaxLength(20).IsRequired();
        builder.Property(x => x.MessageFontFamily).HasMaxLength(100);
        builder.Property(x => x.MessageFontColor).HasMaxLength(20).IsRequired();

        builder.Property(x => x.ImageUrl).HasMaxLength(500);
        builder.Property(x => x.SoundUrl).HasMaxLength(500);
    }
}