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

namespace APT.BaseData.Data.Mapping.FM
{
	public class FMDepartMentMap : TreeEntityBaseMap<T_FM_DEPARTMENT>
    {
		public override void Configure(EntityTypeBuilder<T_FM_DEPARTMENT> builder)
		{
			base.Configure(builder);
			// Properties
			builder.Property(t => t.NAME).HasMaxLength(50);
			builder.Property(t => t.CODE).HasMaxLength(50);
            builder.Property(t => t.NAME_ACRONYM).HasMaxLength(100);
            builder.Property(t => t.REMARK).HasMaxLength(500);
			builder.Property(t => t.LINE_USER).HasMaxLength(500);
			builder.Property(t => t.DEPARTMENT_TYPE).HasDefaultValue(0);
			//builder.HasOne(t => t.Parent).WithMany().HasForeignKey(t => t.PARENT_ID);
			builder.HasOne(t => t.Nav_User).WithMany().HasForeignKey(t => t.USER_ID).OnDelete(DeleteBehavior.Restrict);
			//builder.HasOne(t => t.Nav_Calendar).WithMany().HasForeignKey(t => t.CALENDAR_ID).OnDelete(DeleteBehavior.Restrict);

			//负责人信息
			builder.Property(t => t.PERSON_ID).HasMaxLength(100).IsRequired(false);
			builder.HasOne(t => t.Nav_Person).WithMany().HasForeignKey(t => t.PERSON_ID).IsRequired(false)
				.OnDelete(DeleteBehavior.Restrict);
            builder.HasOne(t => t.Nav_ChargeUser).WithMany().HasForeignKey(t => t.CHARGEUSER_ID).OnDelete(DeleteBehavior.Restrict);
        }
    }
}
