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

namespace Infrastructure.Persistence.Configurations.Payments.Danal;

public class DanalCancelConfiguration : IEntityTypeConfiguration<DanalCancel>
{
    public void Configure(EntityTypeBuilder<DanalCancel> 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);
        builder.HasIndex(x => x.OrderID);
        builder.HasIndex(x => x.MemberID);
        builder.HasIndex(x => x.Method);
        builder.HasIndex(x => x.CancelType);

        builder.ToTable("DanalCancel", 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.CancelRequester).HasMaxLength(20);
        builder.Property(x => x.CancelReason).HasMaxLength(255);
        builder.Property(x => x.ResponseCode).HasMaxLength(20);
        builder.Property(x => x.ResponseMessage).HasMaxLength(500);
        builder.Property(x => x.OriginalTransactionID).HasMaxLength(500);
        builder.Property(x => x.TransDate).HasMaxLength(15);
        builder.Property(x => x.TransTime).HasMaxLength(15);
        builder.Property(x => x.ApprovalDateTime).HasMaxLength(15);
    }
}