using Gebhardt.DbAccess.Base.Configuration;
using Gebhardt.StoreWare.Wcs.Common.DbAccess.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using static Gebhardt.StoreWare.WcsWms.Constants.ModelConstants;

namespace Gebhardt.StoreWare.Wcs.Common.DbAccess.Configuration;

public class OrdersHostEntityConfiguration : BaseEntityConfiguration<OrdersHost>
{
	public override void Configure(EntityTypeBuilder<OrdersHost> builder)
	{
		base.Configure(builder);

		builder.HasIndex(e => new { e.LeNo, e.Status }, "I1_OrdersHost");

		builder.HasIndex(e => new { e.Destination, e.Status }, "I2_OrdersHost");

		builder.HasIndex(e => new { e.Type, e.Status }, "I3_OrdersHost");

		builder.Property(e => e.Destination).IsRequired().HasMaxLength(OrderSourceDestLength);

		builder.Property(e => e.Error).HasMaxLength(ErrorTextLength);

		builder.Property(e => e.IdOrderWms);

		builder.Property(e => e.IdOrderWmsHead);

		builder.Property(e => e.IdOrderWmsPos);

		builder.Property(e => e.DepartureFlag);

		builder.Property(e => e.DepartureLocation);

		builder.Property(e => e.Info).HasMaxLength(InfoTextLength);

		builder.Property(e => e.Source).IsRequired().HasMaxLength(OrderSourceDestLength);

		builder.Property(e => e.Status)
			.IsRequired();

		builder.Property(e => e.Type)
			.IsRequired();


		builder.Property(e => e.LeNo).IsRequired().HasMaxLength(LeNoLength);

		builder.HasOne(e => e.Le).WithMany().HasForeignKey(e => e.LeNo).OnDelete(DeleteBehavior.Cascade);

		builder.HasMany(e => e.Resources).WithOne(e => e.OrdersHost).HasForeignKey(e => e.OrdersHostId).IsRequired();
	}
}