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

namespace Indotalent.Infrastructure.Database.MsSQL.Configuration;

public class TransferOutConfiguration : IEntityTypeConfiguration<TransferOut>
{
    public void Configure(EntityTypeBuilder<TransferOut> builder)
    {
        builder.Property(e => e.AutoNumber)
            .HasMaxLength(GlobalConsts.StringLengthShort);

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

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

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

        builder.HasOne(e => e.WarehouseFrom)
            .WithMany()
            .HasForeignKey(e => e.WarehouseFromId)
            .OnDelete(DeleteBehavior.NoAction);

        builder.HasOne(e => e.WarehouseTo)
            .WithMany()
            .HasForeignKey(e => e.WarehouseToId)
            .OnDelete(DeleteBehavior.NoAction);

        builder.HasIndex(e => new { e.TenantId, e.AutoNumber }).IsUnique();
        builder.HasIndex(e => e.TransferReleaseDate);
        builder.HasIndex(e => e.WarehouseFromId);
        builder.HasIndex(e => e.WarehouseToId);
    }
}