namespace WalletService.Infrastructure.EntityConfigurations;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WalletService.Domain.AggregatesModel.PointAccountAggregate;

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

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

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

        builder.Property(t => t.AccountId)
            .HasColumnName("account_id")
            .IsRequired();

        builder.HasIndex(t => t.AccountId)
            .HasDatabaseName("ix_point_transactions_account_id");

        builder.Property(t => t.Points)
            .HasColumnName("points")
            .IsRequired();

        builder.Property(t => t.TypeId)
            .HasColumnName("type_id")
            .IsRequired();

        builder.Ignore(t => t.Type);

        builder.Property(t => t.Source)
            .HasColumnName("source")
            .HasMaxLength(100)
            .IsRequired();

        builder.Property(t => t.Description)
            .HasColumnName("description")
            .HasMaxLength(500)
            .IsRequired();

        builder.Property(t => t.ExpiresAt)
            .HasColumnName("expires_at");

        builder.Property(t => t.BalanceAfter)
            .HasColumnName("balance_after")
            .IsRequired();

        builder.Property(t => t.CreatedAt)
            .HasColumnName("created_at")
            .IsRequired();

        builder.HasIndex(t => t.CreatedAt)
            .HasDatabaseName("ix_point_transactions_created_at");

        builder.HasIndex(t => t.ExpiresAt)
            .HasDatabaseName("ix_point_transactions_expires_at");

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