using Domain.Entities.Payments;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure.Persistence.Configurations.Payments;

public class PaymentOrderConfiguration : IEntityTypeConfiguration<PaymentOrder>
{
    public void Configure(EntityTypeBuilder<PaymentOrder> builder)
    {
        builder.HasOne(x => x.Member).WithMany().HasForeignKey(x => x.MemberID).OnDelete(DeleteBehavior.NoAction);
        builder.HasIndex(x => x.OrderID).IsUnique();
        builder.HasIndex(x => x.TransactionID);
        builder.HasIndex(x => x.MemberID);
        builder.HasIndex(x => x.Status);

        builder.ToTable(nameof(PaymentOrder), x => x.HasComment("PG 결제 주문"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.OrderID).HasMaxLength(64).IsRequired();
        builder.Property(x => x.MerchantID).HasMaxLength(20).IsRequired();
        builder.Property(x => x.OrderName).HasMaxLength(100).IsRequired();
        builder.Property(x => x.TransactionID).HasMaxLength(64);
        builder.Property(x => x.FailReason).HasMaxLength(500);
        builder.Property(x => x.VirtualAccountNumber).HasMaxLength(64);
        builder.Property(x => x.VirtualAccountBank).HasMaxLength(32);
        builder.Property(x => x.VirtualAccountHolder).HasMaxLength(32);
    }
}