using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Nuuru.Server.Data.EntityConfigurations { public class PostTagConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasKey(pt => new { pt.PostId, pt.TagId }); builder.HasOne(pt => pt.Post) .WithMany(p => p.PostTags) .HasForeignKey(pt => pt.PostId) .OnDelete(DeleteBehavior.Cascade); builder.HasOne(pt => pt.Tag) .WithMany(t => t.PostTags) .HasForeignKey(pt => pt.TagId) .OnDelete(DeleteBehavior.Cascade); builder.HasIndex(pt => pt.AddedAt); builder.HasIndex(pt => pt.IsLocked); // Index for counting posts per tag (TagService.UpdatePostCountAsync) builder.HasIndex(pt => pt.TagId); } } }