using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Nuuru.Server.Data.EntityConfigurations { public class PostFavoriteConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasKey(pf => new { pf.PostId, pf.UserId }); builder.HasOne(pf => pf.Post) .WithMany(p => p.Favorites) .HasForeignKey(pf => pf.PostId) .OnDelete(DeleteBehavior.Cascade); // Cascade delete: when user is deleted, remove their favorites builder.HasOne(pf => pf.User) .WithMany(u => u.BooruPostFavorites) .HasForeignKey(pf => pf.UserId) .OnDelete(DeleteBehavior.Cascade); builder.HasIndex(pf => pf.UserId); builder.HasIndex(pf => pf.CreatedAt); // Index for time-filtered leaderboard queries (join with Post for UploaderId) builder.HasIndex(pf => new { pf.PostId, pf.CreatedAt }); } } }