using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using MembershipService.Domain.AggregatesModel.LevelAggregate;

namespace MembershipService.Infrastructure.EntityConfigurations;

/// <summary>
/// EN: Entity configuration for LevelBenefit entity.
/// VI: Cấu hình entity cho LevelBenefit entity.
/// </summary>
public class LevelBenefitEntityTypeConfiguration : IEntityTypeConfiguration<LevelBenefit>
{
    public void Configure(EntityTypeBuilder<LevelBenefit> builder)
    {
        builder.ToTable("level_benefits");

        // EN: Primary key
        // VI: Primary key
        builder.HasKey(b => b.Id);

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

        // EN: Foreign key to LevelDefinition
        // VI: Foreign key đến LevelDefinition
        builder.Property("_levelDefinitionId")
            .HasColumnName("level_definition_id")
            .IsRequired();

        builder.HasIndex("_levelDefinitionId")
            .HasDatabaseName("ix_level_benefits_level_definition_id");

        // EN: Benefit type
        // VI: Loại benefit
        builder.Property("_benefitType")
            .HasColumnName("benefit_type")
            .HasMaxLength(50)
            .IsRequired();

        // EN: Benefit value (JSON)
        // VI: Giá trị benefit (JSON)
        builder.Property("_benefitValue")
            .HasColumnName("benefit_value")
            .HasColumnType("jsonb")
            .IsRequired();

        // EN: Description
        // VI: Mô tả
        builder.Property("_description")
            .HasColumnName("description");

        // EN: Active status
        // VI: Trạng thái active
        builder.Property("_isActive")
            .HasColumnName("is_active")
            .IsRequired()
            .HasDefaultValue(true);

        // EN: Timestamps
        // VI: Timestamps
        builder.Property("_createdAt")
            .HasColumnName("created_at")
            .IsRequired();

        // EN: Ignore domain events
        // VI: Bỏ qua domain events
        builder.Ignore(b => b.DomainEvents);
    }
}
