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

namespace SportsDivision.Infrastructure.Data.Configurations;

public class RelayTeamMemberConfiguration : IEntityTypeConfiguration<RelayTeamMember>
{
    public void Configure(EntityTypeBuilder<RelayTeamMember> builder)
    {
        builder.HasKey(r => r.RelayTeamMemberId);
        builder.HasOne(r => r.RelayTeam).WithMany(rt => rt.Members).HasForeignKey(r => r.RelayTeamId).OnDelete(DeleteBehavior.Cascade);
        builder.HasOne(r => r.Student).WithMany().HasForeignKey(r => r.StudentId).OnDelete(DeleteBehavior.Restrict);
        builder.HasIndex(r => new { r.RelayTeamId, r.StudentId }).IsUnique();
    }
}
