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

namespace Infrastructure.Persistence.Configurations.Donations;

public class CrewMemberConfiguration : IEntityTypeConfiguration<CrewMember>
{
    public void Configure(EntityTypeBuilder<CrewMember> builder)
    {
        builder.ToTable(nameof(CrewMember), x => x.HasComment("크루원"));
        builder.HasKey(x => x.ID);

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

        builder.HasIndex(x => new { x.CrewID, x.MemberID }).IsUnique();

        builder.Property(x => x.Nickname).HasMaxLength(40).IsRequired();
        builder.Property(x => x.Role).HasMaxLength(50);
    }
}