using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Tiku.Domain.Catalog; namespace Tiku.Infrastructure.Persistence.Configurations; internal sealed class ScorelineFieldConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ConfigureTenantEntity("scoreline_fields"); builder.ConfigureTimestamps(); builder.Property(entity => entity.LegacyId).HasMaxLength(64); builder.Property(entity => entity.FieldKey).HasMaxLength(64); builder.Property(entity => entity.FieldName).HasMaxLength(200); builder.Property(entity => entity.FieldType).HasMaxLength(32); builder.Property(entity => entity.Unit).HasMaxLength(32); builder.Property(entity => entity.Options).IsJson("[]"); builder.Property(entity => entity.Placeholder).HasMaxLength(200); builder.Property(entity => entity.Description).HasMaxLength(1000); builder.HasIndex(entity => new { entity.TenantId, entity.LegacyId }).IsUnique(); builder.HasIndex(entity => new { entity.TenantId, entity.RegionId, entity.FieldKey }).IsUnique(); builder.HasIndex(entity => new { entity.TenantId, entity.RegionId, entity.IsFilter, entity.SortOrder }); builder.HasOne() .WithMany() .HasForeignKey(entity => new { entity.TenantId, entity.RegionId }) .HasPrincipalKey(entity => new { entity.TenantId, entity.Id }) .OnDelete(DeleteBehavior.Restrict); } } internal sealed class ScorelineRecordConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ConfigureTenantEntity("scoreline_records"); builder.ConfigureTimestamps(); builder.Property(entity => entity.LegacyId).HasMaxLength(64); builder.Property(entity => entity.SchoolName).HasMaxLength(300); builder.Property(entity => entity.MajorName).HasMaxLength(300); builder.Property(entity => entity.FieldValues).IsJson("{}"); builder.HasIndex(entity => new { entity.TenantId, entity.LegacyId }).IsUnique(); builder.HasIndex(entity => new { entity.TenantId, entity.RegionId, entity.SchoolId, entity.MajorId, entity.Year }); builder.HasIndex(entity => new { entity.TenantId, entity.Year }); builder.HasOne() .WithMany() .HasForeignKey(entity => new { entity.TenantId, entity.RegionId }) .HasPrincipalKey(entity => new { entity.TenantId, entity.Id }) .OnDelete(DeleteBehavior.Restrict); builder.HasOne() .WithMany() .HasForeignKey(entity => new { entity.TenantId, entity.SchoolId }) .HasPrincipalKey(entity => new { entity.TenantId, entity.Id }) .OnDelete(DeleteBehavior.Restrict); builder.HasOne() .WithMany() .HasForeignKey(entity => new { entity.TenantId, entity.MajorId }) .HasPrincipalKey(entity => new { entity.TenantId, entity.Id }) .OnDelete(DeleteBehavior.Restrict); } }