using APT.BaseData.Domain.Entities;
using APT.Infrastructure.EF.Map;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace APT.BaseData.Data.Mapping
{
	public class PFPageTableMap : TreeEntityBaseMap<T_PF_PAGE_TABLE>
    {
		public override void Configure(EntityTypeBuilder<T_PF_PAGE_TABLE> builder)
		{
			base.Configure(builder);
			builder.Property(t => t.TABLE_NAME).HasMaxLength(200);
			builder.Property(t => t.TITLE).HasMaxLength(50);
			builder.Property(t => t.DATA_TABLE).HasMaxLength(200);
			builder.Property(t => t.LABEL_NAME).HasMaxLength(200);
			builder.Property(t => t.TABLE_CONDITION).HasMaxLength(100);
			builder.Property(t => t.API_URL).HasMaxLength(100);
			builder.Property(t => t.DEL_API_URL).HasMaxLength(100);
			builder.Property(t => t.BATCH_DEL_API_URL).HasMaxLength(100);
			builder.Property(t => t.SEND_TYPE).HasMaxLength(50);
			builder.Property(t => t.SORT).HasMaxLength(50);
			builder.Property(t => t.SORTS).HasMaxLength(200);
			builder.Property(t => t.ORDERS).HasMaxLength(200);
			builder.Property(t => t.CLASS_FIELD).HasMaxLength(200);
			builder.Property(t => t.PIC_CODE_FIELD).HasMaxLength(50);
			builder.Property(t => t.POSITION).HasMaxLength(20);
			builder.Property(t => t.RELATION_FIELD).HasMaxLength(50);

			builder.HasMany(t => t.Nav_TableParams).
				WithOne(t => t.Nav_PageTable).HasForeignKey(t => t.PAGE_TABLE_ID).OnDelete(DeleteBehavior.Restrict);

			builder.HasOne(t => t.Nav_PageForm).
				WithMany().HasForeignKey(t => t.PAGE_FORM_ID).OnDelete(DeleteBehavior.Restrict);
			builder.Property(t => t.CODE).HasMaxLength(100);
			builder.Property(t => t.CLASS_FUNC_NAME).HasMaxLength(200);
			builder.Property(t => t.CUSTOM_PARAMS).HasMaxLength(200); 
			builder.Property(t => t.PARENT_RELATION_FIELD).HasMaxLength(200); 

			builder.HasOne(t => t.Nav_ParamScheme).
				WithMany(t=>t.Nav_PageTables).HasForeignKey(t => t.PARAM_SCHEME_ID).OnDelete(DeleteBehavior.Restrict);


			builder.HasMany(t => t.Nav_Columns).
				WithOne(t => t.Nav_PageTable).HasForeignKey(t => t.PAGE_TABLE_ID).OnDelete(DeleteBehavior.Restrict);

			builder.HasMany(t => t.Nav_Btns).
			WithOne().HasForeignKey(t => t.PAGE_TABLE_ID).OnDelete(DeleteBehavior.Restrict);


		}

	}
}
