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

namespace Infrastructure.Persistence.Configurations.Donations;

public class SettlementAccountConfiguration : IEntityTypeConfiguration<SettlementAccount>
{
    public void Configure(EntityTypeBuilder<SettlementAccount> builder)
    {
        builder.ToTable(nameof(SettlementAccount), 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.ChannelID, x.MemberID });

        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);
    }
}