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

namespace SportsDivision.Infrastructure.Data.Configurations;

public class HighJumpAttemptConfiguration : IEntityTypeConfiguration<HighJumpAttempt>
{
    public void Configure(EntityTypeBuilder<HighJumpAttempt> builder)
    {
        builder.HasKey(a => a.HighJumpAttemptId);
        builder.Property(a => a.Attempt1).HasConversion<string>().HasMaxLength(10);
        builder.Property(a => a.Attempt2).HasConversion<string>().HasMaxLength(10);
        builder.Property(a => a.Attempt3).HasConversion<string>().HasMaxLength(10);
        builder.HasOne(a => a.HighJumpHeight).WithMany(h => h.Attempts).HasForeignKey(a => a.HighJumpHeightId).OnDelete(DeleteBehavior.Cascade);
        builder.HasOne(a => a.EventRegistration).WithMany().HasForeignKey(a => a.EventRegistrationId).OnDelete(DeleteBehavior.Restrict);
        builder.HasIndex(a => new { a.HighJumpHeightId, a.EventRegistrationId }).IsUnique();
        builder.Ignore(a => a.IsEliminated);
        builder.Ignore(a => a.HasCleared);
        builder.Ignore(a => a.FailCount);
    }
}
