using DiplomovaPrace.Model.Products;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace DiplomovaPrace.Entity.Configurations.Products
{
	public class ProductCategoryConfiguration : IEntityTypeConfiguration<ProductCategory>
	{
		public void Configure(EntityTypeBuilder<ProductCategory> builder)
		{
			builder.HasData(new ProductCategory { ID = (int)ProductCategory.Entry.Root, Name = "Root", ParentID = (int)ProductCategory.Entry.Root });

			builder.HasOne(parent => parent.Parent)
				.WithMany(descendant => descendant.Descendants)
				.HasForeignKey(parent => parent.ParentID)
				.OnDelete(DeleteBehavior.NoAction);
		}
	}
}
