using Lada.Framework.Data.Domains.Cms;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Lada.Framework.Data.Mappings.EntityMappings.Cms
{
    public class ProductTagMap : IEntityMappingConfiguration<ProductTag>
    {
        public void Map(EntityTypeBuilder<ProductTag> builder)
        {
            builder.HasKey(pc => new { pc.ProductId, pc.TagId });
            builder.HasOne(pc => pc.Product).WithMany(p => p.ProductTags).HasForeignKey(pc => pc.ProductId);
            builder.HasOne(pc => pc.Tag).WithMany(p => p.ProductTags).HasForeignKey(pc => pc.TagId);
            builder.ToTable("ProductTag");
        }
    }
}
