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

namespace CMSMicroservice.Infrastructure.Persistence.Configurations.Blog;

public class BlogPostTagConfiguration : IEntityTypeConfiguration<BlogPostTag>
{
    public void Configure(EntityTypeBuilder<BlogPostTag> builder)
    {
        builder.ToTable("BlogPostTags");
        builder.HasKey(e => e.Id);

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

        builder.HasOne(d => d.Tag)
            .WithMany()
            .HasForeignKey(d => d.TagId);
    }
}
