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

namespace Infrastructure.Persistence.Configurations.Donations;

public class WithdrawalRequestConfiguration : IEntityTypeConfiguration<WithdrawalRequest>
{
    public void Configure(EntityTypeBuilder<WithdrawalRequest> builder)
    {
        builder.ToTable(nameof(WithdrawalRequest), x => x.HasComment("출금 요청"));
        builder.HasKey(x => x.ID);

        builder.HasOne(x => x.Channel).WithMany().HasForeignKey(x => x.ChannelID).OnDelete(DeleteBehavior.NoAction);
        builder.HasOne(x => x.Member).WithMany().HasForeignKey(x => x.MemberID).OnDelete(DeleteBehavior.NoAction);

        builder.HasIndex(x => new { x.MemberID, x.RequestedAt });
        builder.HasIndex(x => new { x.MemberID, x.Status });

        builder.Property(x => x.BankCode).HasMaxLength(10);
        builder.Property(x => x.BankName).HasMaxLength(50);
        builder.Property(x => x.AccountNumber).HasMaxLength(500);
        builder.Property(x => x.AccountHolder).HasMaxLength(100);
        builder.Property(x => x.RejectedReason).HasMaxLength(500);
        builder.Property(x => x.AdminMemo).HasMaxLength(500);
    }
}