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

namespace SportsDivision.Infrastructure.Data.Configurations;

public class HeatLaneConfiguration : IEntityTypeConfiguration<HeatLane>
{
    public void Configure(EntityTypeBuilder<HeatLane> builder)
    {
        builder.HasKey(h => h.HeatLaneId);
        builder.Property(h => h.Time).HasPrecision(10, 3);
        builder.Property(h => h.AdvanceReason).HasConversion<string>().HasMaxLength(20);
        builder.Property(h => h.RecordedBy).HasMaxLength(450);
        builder.HasOne(h => h.Heat).WithMany(he => he.HeatLanes).HasForeignKey(h => h.HeatId).OnDelete(DeleteBehavior.Cascade);
        builder.HasOne(h => h.EventRegistration).WithMany(r => r.HeatLanes).HasForeignKey(h => h.EventRegistrationId).OnDelete(DeleteBehavior.Restrict);
        builder.HasIndex(h => new { h.HeatId, h.LaneNumber }).IsUnique();
    }
}
