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

namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
public class ProductCategoryConfiguration : IEntityTypeConfiguration<ProductCategory>
{
    public void Configure(EntityTypeBuilder<ProductCategory> builder)
    {
        builder.HasQueryFilter(p => !p.IsDeleted);
        builder.ToTable("ProductCategories", "CMS");
        builder.HasKey(e => e.Id);
        
        builder.HasOne(d => d.Product)
            .WithMany(p => p.ProductCategories)
            .HasForeignKey(d => d.ProductId);
        
        builder.HasOne(d => d.Category)
            .WithMany(p => p.ProductCategories)
            .HasForeignKey(d => d.CategoryId);
    }
}
