using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Nuuru.Server.Models.Booru; namespace Nuuru.Server.Data.EntityConfigurations { public class TagHistoryConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { // Index for finding all history entries for a post builder.HasIndex(h => h.PostId); // Composite index for chronological history per post builder.HasIndex(h => new { h.PostId, h.DateSet }); // Index for user activity queries builder.HasIndex(h => h.UserId); // Cascade delete when post is deleted builder.HasOne(h => h.Post) .WithMany() .HasForeignKey(h => h.PostId) .OnDelete(DeleteBehavior.Cascade); // Cascade delete when user is deleted builder.HasOne(h => h.User) .WithMany() .HasForeignKey(h => h.UserId) .OnDelete(DeleteBehavior.Cascade); // SetNull on SuppressedBy (if moderator is deleted, keep history but clear suppressor) builder.HasOne(h => h.SuppressedBy) .WithMany() .HasForeignKey(h => h.SuppressedById) .OnDelete(DeleteBehavior.SetNull); } } public class SourceHistoryConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { // Index for finding all history entries for a post builder.HasIndex(h => h.PostId); // Composite index for chronological history per post builder.HasIndex(h => new { h.PostId, h.DateSet }); // Index for user activity queries builder.HasIndex(h => h.UserId); // Cascade delete when post is deleted builder.HasOne(h => h.Post) .WithMany() .HasForeignKey(h => h.PostId) .OnDelete(DeleteBehavior.Cascade); // Cascade delete when user is deleted builder.HasOne(h => h.User) .WithMany() .HasForeignKey(h => h.UserId) .OnDelete(DeleteBehavior.Cascade); // SetNull on SuppressedBy (if moderator is deleted, keep history but clear suppressor) builder.HasOne(h => h.SuppressedBy) .WithMany() .HasForeignKey(h => h.SuppressedById) .OnDelete(DeleteBehavior.SetNull); } } }