using Indotalent.Data.Entities;
using Indotalent.Shared.Consts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Indotalent.Infrastructure.Database.MsSQL.Configuration;

public class PaymentDisburseConfiguration : IEntityTypeConfiguration<PaymentDisburse>
{
    public void Configure(EntityTypeBuilder<PaymentDisburse> builder)
    {
        builder.Property(e => e.BillId)
            .HasMaxLength(GlobalConsts.StringLengthId);

        builder.Property(e => e.AutoNumber)
            .HasMaxLength(GlobalConsts.StringLengthShort);

        builder.Property(e => e.Description)
            .HasMaxLength(GlobalConsts.StringLengthMedium);

        builder.Property(e => e.PaymentMethodId)
            .HasMaxLength(GlobalConsts.StringLengthId);

        builder.HasOne(e => e.Bill)
            .WithMany()
            .HasForeignKey(e => e.BillId)
            .OnDelete(DeleteBehavior.NoAction);

        builder.HasOne(e => e.PaymentMethod)
            .WithMany()
            .HasForeignKey(e => e.PaymentMethodId)
            .OnDelete(DeleteBehavior.NoAction);

        builder.HasIndex(e => e.AutoNumber).IsUnique();
        builder.HasIndex(e => e.BillId);
        builder.HasIndex(e => e.PaymentMethodId);
        builder.HasIndex(e => e.PaymentDate);
    }
}