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

namespace Infrastructure.Persistence.Configurations.Donations;

public class DonationRankConfigConfiguration : IEntityTypeConfiguration<DonationRankConfig>
{
    public void Configure(EntityTypeBuilder<DonationRankConfig> builder)
    {
        builder.ToTable(nameof(DonationRankConfig), 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 => x.ChannelID);

        builder.Property(x => x.Title).HasMaxLength(300).IsRequired();
    }
}