using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Nashel.BuildingBlocks.Domain; using Nashel.Modules.Identity.Domain.Aggregates; using Nashel.Modules.Identity.Domain.Entities; namespace Nashel.Modules.Identity.Infrastructure.Persistence.Configurations; public class UserProfileConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("UserProfiles", "identity"); builder.HasKey(x => x.Id); builder.Property(x => x.FirstName) .IsRequired() .HasMaxLength(100); builder.Property(x => x.LastName) .IsRequired() .HasMaxLength(100); builder.Property(x => x.Patronymic) .HasMaxLength(100); builder.Property(x => x.CompanyName) .HasMaxLength(200); builder.Property(x => x.Inn) .HasMaxLength(10); builder.Property(x => x.Description) .HasMaxLength(2048); builder.Property(x => x.AvatarUrl) .HasMaxLength(500); // Optional 1:1 relationship with WorkSchedule builder.HasOne(x => x.WorkSchedule) .WithOne() .HasForeignKey(x => x.Id) .OnDelete(DeleteBehavior.Cascade); // Many-to-Many relationship with Competencies builder.HasMany(x => x.Competencies) .WithMany() .UsingEntity>( "UserProfileCompetencies", j => j.HasOne().WithMany().HasForeignKey("CompetencyId"), j => j.HasOne().WithMany().HasForeignKey("UserProfileId"), j => { j.ToTable("UserProfileCompetencies", "identity"); j.HasKey("UserProfileId", "CompetencyId"); }); // 1:1 relationship with Account builder.HasOne() .WithOne(x => x.Profile) .HasForeignKey(x => x.Id) .OnDelete(DeleteBehavior.Cascade); } }