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

namespace Infrastructure.Persistence.Configurations.Donations;

public class DonationMetaConfiguration : IEntityTypeConfiguration<DonationMeta>
{
    public void Configure(EntityTypeBuilder<DonationMeta> builder)
    {
        builder.ToTable(nameof(DonationMeta), 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 }).IsUnique();
    }
}