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

namespace SportsDivision.Infrastructure.Data.Configurations;

public class TournamentEventLevelConfiguration : IEntityTypeConfiguration<TournamentEventLevel>
{
    public void Configure(EntityTypeBuilder<TournamentEventLevel> builder)
    {
        builder.HasKey(t => t.TournamentEventLevelId);
        builder.HasIndex(t => new { t.TournamentId, t.EventId, t.EventLevelId }).IsUnique();
        builder.HasOne(t => t.Tournament).WithMany(to => to.TournamentEventLevels).HasForeignKey(t => t.TournamentId).OnDelete(DeleteBehavior.Cascade);
        builder.HasOne(t => t.Event).WithMany(e => e.TournamentEventLevels).HasForeignKey(t => t.EventId).OnDelete(DeleteBehavior.Restrict);
        builder.HasOne(t => t.EventLevel).WithMany(el => el.TournamentEventLevels).HasForeignKey(t => t.EventLevelId).OnDelete(DeleteBehavior.Restrict);
    }
}
