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

namespace Infrastructure.Persistence.Configurations.Payments.Danal;

public class DanalLogConfiguration : IEntityTypeConfiguration<DanalLog>
{
    public void Configure(EntityTypeBuilder<DanalLog> builder)
    {
        builder.HasOne(x => x.Member).WithMany().HasForeignKey(x => x.MemberID).OnDelete(DeleteBehavior.NoAction);
        builder.HasIndex(x => x.MemberID);
        builder.HasIndex(x => x.LogType);
        builder.HasIndex(x => x.Code);
        builder.HasIndex(x => x.TransactionID);
        builder.HasIndex(x => x.OrderID);

        builder.ToTable("DanalLog", x => x.HasComment("다날 결제 에러/실패/웹훅 로그"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.Code).HasMaxLength(20).IsRequired();
        builder.Property(x => x.Message).HasMaxLength(500).IsRequired();
        builder.Property(x => x.TransactionID).HasMaxLength(64);
        builder.Property(x => x.OrderID).HasMaxLength(64);
        builder.Property(x => x.ExtraData).HasMaxLength(4000);
    }
}