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

namespace UniVerse.Infrastructure.Data.Configurations;

public class StudentProfileConfiguration : IEntityTypeConfiguration<StudentProfile>
{
    public void Configure(EntityTypeBuilder<StudentProfile> builder)
    {
        builder.ToTable("student_profiles");

        builder.HasKey(s => s.Id);
        builder.Property(s => s.Id).HasColumnName("id");
        builder.Property(s => s.UserId).HasColumnName("user_id");
        builder.Property(s => s.StudentId).HasColumnName("student_id").HasMaxLength(50);
        builder.Property(s => s.GroupName).HasColumnName("group_name").HasMaxLength(100);
        builder.Property(s => s.EnrollmentYear).HasColumnName("enrollment_year");
        builder.Property(s => s.Faculty).HasColumnName("faculty").HasMaxLength(255);
        builder.Property(s => s.Specialty).HasColumnName("specialty").HasMaxLength(255);

        builder.HasOne(s => s.User)
            .WithOne(u => u.StudentProfile)
            .HasForeignKey<StudentProfile>(s => s.UserId)
            .OnDelete(DeleteBehavior.Cascade);

        builder.HasIndex(s => s.UserId).IsUnique();
    }
}
