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

namespace SportsDivision.Infrastructure.Data.Configurations;

public class SchoolConfiguration : IEntityTypeConfiguration<School>
{
    public void Configure(EntityTypeBuilder<School> builder)
    {
        builder.HasKey(s => s.SchoolId);
        builder.Property(s => s.Name).IsRequired().HasMaxLength(200);
        builder.Property(s => s.ShortName).HasMaxLength(20);
        builder.Property(s => s.SchoolLevel).HasConversion<string>().HasMaxLength(20);
        builder.HasOne(s => s.Zone).WithMany(z => z.Schools).HasForeignKey(s => s.ZoneId).OnDelete(DeleteBehavior.Restrict);
        builder.HasIndex(s => s.Name).IsUnique();
    }
}
