// EN: Category entity configuration.
// VI: Cấu hình entity Category.

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using CatalogService.Domain.AggregatesModel.ProductAggregate;

namespace CatalogService.Infrastructure.EntityConfigurations;

/// <summary>
/// EN: EF Core configuration for Category entity.
/// VI: Cấu hình EF Core cho Category entity.
/// </summary>
public class CategoryEntityTypeConfiguration : IEntityTypeConfiguration<Category>
{
    public void Configure(EntityTypeBuilder<Category> builder)
    {
        builder.ToTable("categories");

        builder.HasKey(c => c.Id);

        builder.Property(c => c.Id)
            .HasColumnName("id")
            .ValueGeneratedNever();

        builder.Property<Guid>("_shopId")
            .HasColumnName("shop_id")
            .IsRequired();

        builder.Property<string>("_name")
            .HasColumnName("name")
            .HasMaxLength(200)
            .IsRequired();

        builder.Property<string?>("_description")
            .HasColumnName("description")
            .HasMaxLength(1000);

        builder.Property<Guid?>("_parentId")
            .HasColumnName("parent_id");

        builder.Property<int>("_displayOrder")
            .HasColumnName("display_order")
            .HasDefaultValue(0);

        builder.Property<bool>("_isActive")
            .HasColumnName("is_active")
            .HasDefaultValue(true);

        builder.Property<DateTime>("_createdAt")
            .HasColumnName("created_at")
            .IsRequired();

        builder.Property<DateTime?>("_updatedAt")
            .HasColumnName("updated_at");

        // EN: Indexes
        // VI: Indexes
        builder.HasIndex("_shopId").HasDatabaseName("ix_categories_shop_id");
        builder.HasIndex("_parentId").HasDatabaseName("ix_categories_parent_id");
        builder.HasIndex("_displayOrder").HasDatabaseName("ix_categories_display_order");

        // EN: Ignore calculated properties
        // VI: Bỏ qua các properties được tính toán
        builder.Ignore(c => c.ShopId);
        builder.Ignore(c => c.Name);
        builder.Ignore(c => c.Description);
        builder.Ignore(c => c.ParentId);
        builder.Ignore(c => c.DisplayOrder);
        builder.Ignore(c => c.IsActive);
        builder.Ignore(c => c.CreatedAt);
        builder.Ignore(c => c.UpdatedAt);
    }
}
