using CMSMicroservice.Domain.Entities.Blog;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CMSMicroservice.Infrastructure.Persistence.Configurations.Blog;

public class BlogPostCategoryConfiguration : IEntityTypeConfiguration<BlogPostCategory>
{
    public void Configure(EntityTypeBuilder<BlogPostCategory> builder)
    {
        builder.ToTable("BlogPostCategories");
        builder.HasKey(e => e.Id);

        builder.HasOne(d => d.BlogPost)
            .WithMany(p => p.BlogPostCategories)
            .HasForeignKey(d => d.BlogPostId);

        builder.HasOne(d => d.BlogCategory)
            .WithMany(p => p.BlogPostCategories)
            .HasForeignKey(d => d.BlogCategoryId);
    }
}
