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

namespace Infrastructure.Persistence.Configurations.Payments.Danal;

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

        builder.ToTable("DanalConfirm", x => x.HasComment("다날 결제 승인 (요청+응답)"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.TransactionID).HasMaxLength(64).IsRequired();
        builder.Property(x => x.OrderID).HasMaxLength(64).IsRequired();
        builder.Property(x => x.MerchantID).HasMaxLength(20).IsRequired();
        builder.Property(x => x.CertificateToken).HasMaxLength(200);
        builder.Property(x => x.ResponseCode).HasMaxLength(20);
        builder.Property(x => x.ResponseMessage).HasMaxLength(500);
        builder.Property(x => x.OrderName).HasMaxLength(500);
        builder.Property(x => x.UserName).HasMaxLength(20);
        builder.Property(x => x.TransDate).HasMaxLength(8);
        builder.Property(x => x.TransTime).HasMaxLength(20);
        builder.Property(x => x.CardCode).HasMaxLength(20);
        builder.Property(x => x.CardName).HasMaxLength(100);
        builder.Property(x => x.CardNo).HasMaxLength(64);
        builder.Property(x => x.ApproveNo).HasMaxLength(50);
        builder.Property(x => x.ApprovalDateTime).HasMaxLength(15);
        builder.Property(x => x.AuthKey).HasMaxLength(100);
        builder.Property(x => x.AccountNumber).HasMaxLength(100);
        builder.Property(x => x.BankCode).HasMaxLength(3);
        builder.Property(x => x.UserId).HasMaxLength(20);
        builder.Property(x => x.UserEmail).HasMaxLength(60);
        builder.Property(x => x.BankName).HasMaxLength(20);
        builder.Property(x => x.ExpireDate).HasMaxLength(10);
        builder.Property(x => x.ExpireTime).HasMaxLength(15);
        builder.Property(x => x.VirtualAccountNumber).HasMaxLength(30);
        builder.Property(x => x.UseCashReceipt).HasMaxLength(1);
    }
}