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

namespace SportsDivision.Infrastructure.Data.Configurations;

public class StudentConfiguration : IEntityTypeConfiguration<Student>
{
    public void Configure(EntityTypeBuilder<Student> builder)
    {
        builder.HasKey(s => s.StudentId);
        builder.Property(s => s.ExistingStudentId).IsRequired().HasMaxLength(50);
        builder.HasIndex(s => s.ExistingStudentId).IsUnique();
        builder.Property(s => s.FirstName).IsRequired().HasMaxLength(100);
        builder.Property(s => s.LastName).IsRequired().HasMaxLength(100);
        builder.Property(s => s.Sex).HasConversion<string>().HasMaxLength(10);
        builder.HasOne(s => s.School).WithMany(sc => sc.Students).HasForeignKey(s => s.SchoolId).OnDelete(DeleteBehavior.Restrict);
        builder.Ignore(s => s.FullName);
    }
}
