using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using FnbEngine.Domain.AggregatesModel.RecipeAggregate;

namespace FnbEngine.Infrastructure.EntityConfigurations;

public class RecipeIngredientEntityTypeConfiguration : IEntityTypeConfiguration<RecipeIngredient>
{
    public void Configure(EntityTypeBuilder<RecipeIngredient> builder)
    {
        builder.ToTable("recipe_ingredients");
        builder.HasKey(ri => ri.Id);
        builder.Property(ri => ri.Id).HasColumnName("id").ValueGeneratedNever();
        builder.Property(ri => ri.RecipeId).HasField("_recipeId").HasColumnName("recipe_id").IsRequired();
        builder.Property(ri => ri.IngredientName).HasField("_ingredientName").HasColumnName("ingredient_name").HasMaxLength(200).IsRequired();
        builder.Property(ri => ri.Quantity).HasField("_quantity").HasColumnName("quantity").HasColumnType("decimal(18,4)").IsRequired();
        builder.Property(ri => ri.Unit).HasField("_unit").HasColumnName("unit").HasMaxLength(50).IsRequired();
        builder.Property(ri => ri.CostPerUnit).HasField("_costPerUnit").HasColumnName("cost_per_unit").HasColumnType("decimal(18,2)");

        // EN: Optional inventory item link for COGS calculation / VI: Liên kết tùy chọn đến mặt hàng tồn kho để tính giá vốn
        builder.Property(ri => ri.InventoryItemId).HasField("_inventoryItemId").HasColumnName("inventory_item_id");
        builder.Property(ri => ri.QuantityPerServing).HasField("_quantityPerServing").HasColumnName("quantity_per_serving").HasColumnType("decimal(18,4)");

        builder.Ignore(ri => ri.DomainEvents);
    }
}
