using Core.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Data.Configurations
{
    public class StudentEventRankingConfiguration : IEntityTypeConfiguration<StudentEventRanking>
    {
        public void Configure(EntityTypeBuilder<StudentEventRanking> builder)
        {
            // Note: Relationships are configured in StudentConfiguration
            // This configuration only defines keys, indexes, and constraints

            // Composite key on shadow properties created by EF Core
            builder.HasKey("StudentId", "EventDefinitionId");

            // Indexes on shadow properties
            builder.HasIndex(r => r.Rank);
            builder.HasIndex("StudentId");
            builder.HasIndex("EventDefinitionId");

            // Constraints
            builder.Property(r => r.Rank)
                .IsRequired();

            // Relationship to EventDefinition (Student relationship is in StudentConfiguration)
            builder.HasOne(r => r.EventDefinition)
                .WithMany()
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);
        }
    }
}
