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

namespace Infrastructure.Persistence.Configurations.Donations;

public class DonationGoalConfigConfiguration : IEntityTypeConfiguration<DonationGoalConfig>
{
    public void Configure(EntityTypeBuilder<DonationGoalConfig> builder)
    {
        builder.ToTable(nameof(DonationGoalConfig), 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 });
        builder.HasIndex(x => new { x.ChannelID, x.IsActive });

        builder.Property(x => x.Title).HasMaxLength(50).IsRequired();
        builder.Property(x => x.BarColor).HasMaxLength(9);
        builder.Property(x => x.BarBackgroundColor).HasMaxLength(9);
        builder.Property(x => x.TitleFontColor).HasMaxLength(9);
        builder.Property(x => x.AmountFontColor).HasMaxLength(9);
        builder.Property(x => x.TitleFontFamily).HasMaxLength(100);
        builder.Property(x => x.AmountFontFamily).HasMaxLength(100);
    }
}