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

namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
public class ProductTagConfiguration : IEntityTypeConfiguration<ProductTag>
{
    public void Configure(EntityTypeBuilder<ProductTag> builder)
    {
        builder.HasQueryFilter(p => !p.IsDeleted);
        builder.ToTable("ProductTags", "CMS");
        builder.HasKey(e => e.Id);
        
        builder.HasOne(d => d.Product)
            .WithMany(p => p.ProductTags)
            .HasForeignKey(d => d.ProductId);
        
        builder.HasOne(d => d.Tag)
            .WithMany(p => p.ProductTags)
            .HasForeignKey(d => d.TagId);
    }
}
