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

namespace Infrastructure.Persistence.Configurations.Donations;

public class CrewSessionConsentConfiguration : IEntityTypeConfiguration<CrewSessionConsent>
{
    public void Configure(EntityTypeBuilder<CrewSessionConsent> builder)
    {
        builder.ToTable(nameof(CrewSessionConsent), x => x.HasComment("크루원 방송 동의"));
        builder.HasKey(x => x.ID);

        builder.HasOne(x => x.CrewSession).WithMany(x => x.Consents).HasForeignKey(x => x.CrewSessionID).OnDelete(DeleteBehavior.Cascade);
        builder.HasOne(x => x.CrewMember).WithMany().HasForeignKey(x => x.CrewMemberID).OnDelete(DeleteBehavior.NoAction);

        builder.HasIndex(x => new { x.CrewSessionID, x.CrewMemberID }).IsUnique();
    }
}