using CMSMicroservice.Domain.Entities.Payment;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CMSMicroservice.Infrastructure.Persistence.Configurations;

public class PaymentTransactionConfiguration : IEntityTypeConfiguration<PaymentTransaction>
{
    public void Configure(EntityTypeBuilder<PaymentTransaction> builder)
    {
        builder.HasQueryFilter(p => !p.IsDeleted);
        builder.Ignore(entity => entity.DomainEvents);
        builder.HasKey(entity => entity.Id);
        builder.Property(entity => entity.Id).UseIdentityColumn();

        // اطلاعات درخواست
        builder.Property(e => e.GatewayProvider).IsRequired().HasMaxLength(50);
        builder.Property(e => e.MerchantId).IsRequired().HasMaxLength(200);
        builder.Property(e => e.Amount).IsRequired();
        builder.Property(e => e.CallbackUrl).IsRequired().HasMaxLength(500);
        builder.Property(e => e.Description).IsRequired().HasMaxLength(500);
        builder.Property(e => e.Mobile).HasMaxLength(20);
        builder.Property(e => e.UserId);

        // پاسخ درخواست
        builder.Property(e => e.RequestStatusCode);
        builder.Property(e => e.RequestStatusMessage).HasMaxLength(500);
        builder.Property(e => e.Authority).HasMaxLength(200);

        // وضعیت پرداخت
        builder.Property(e => e.PaymentStatus).IsRequired();

        // نتیجه verify
        builder.Property(e => e.VerificationStatusCode);
        builder.Property(e => e.VerificationStatusMessage).HasMaxLength(500);
        builder.Property(e => e.CardHash).HasMaxLength(200);
        builder.Property(e => e.CardPan).HasMaxLength(30);
        builder.Property(e => e.RefId).HasMaxLength(200);

        // ارتباط داخلی
        builder.Property(e => e.TransactionId);
        builder.Property(e => e.OrderId).HasMaxLength(100);

        // ایندکس‌ها
        builder.HasIndex(e => e.Authority);
        builder.HasIndex(e => e.GatewayProvider);
        builder.HasIndex(e => e.UserId);
        builder.HasIndex(e => e.TransactionId);
        builder.HasIndex(e => e.RefId);
    }
}
