using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Nuuru.Server.Models.Booru; namespace Nuuru.Server.Data.EntityConfigurations { public class TagImplicationConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasKey(i => i.Id); // Same implication cannot exist twice builder.HasIndex(i => new { i.AntecedentTagId, i.ConsequentTagId }).IsUnique(); // Index for looking up implications by consequent (what implies this tag) builder.HasIndex(i => i.ConsequentTagId); // Index for filtering by active status and creation date builder.HasIndex(i => i.IsActive); builder.HasIndex(i => i.CreatedAt); // Relationships builder.HasOne(i => i.AntecedentTag) .WithMany(t => t.ImplicationsAsAntecedent) .HasForeignKey(i => i.AntecedentTagId) .OnDelete(DeleteBehavior.Cascade); builder.HasOne(i => i.ConsequentTag) .WithMany(t => t.ImplicationsAsConsequent) .HasForeignKey(i => i.ConsequentTagId) .OnDelete(DeleteBehavior.Cascade); builder.HasOne(i => i.CreatedBy) .WithMany() .HasForeignKey(i => i.CreatedByUserId) .OnDelete(DeleteBehavior.SetNull); } } }