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 FMUserMap : APTEntityBaseMap<T_FM_USER>
    {
        public override void Configure(EntityTypeBuilder<T_FM_USER> builder)
        {
            base.Configure(builder);
            builder.Property(t => t.NAME)
               .HasMaxLength(50);

            builder.Property(t => t.NAME_ACRONYM).HasMaxLength(100);
            builder.Property(t => t.CODE).IsRequired()
              .HasMaxLength(50);


            builder.Property(t => t.PHONE)
              .HasMaxLength(50);

            builder.Property(t => t.PASSWORD)
              .HasMaxLength(128);
            

            builder.Property(t => t.REMARK).HasMaxLength(300);

            builder.HasOne(t => t.Nav_Department).WithMany(t => t.Nav_UserList).HasForeignKey(t => t.DEPARTMENT_ID).OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(t => t.Nav_Person).WithOne(t => t.Nav_User).HasForeignKey<T_FM_USER>(t => t.PERSON_ID).OnDelete(DeleteBehavior.Restrict);
            builder.Ignore(t => t.TEAMNAME);
            builder.Ignore(t => t.Team);
            builder.Property(t => t.ID_CARD)
              .HasMaxLength(50);
            builder.HasOne(t => t.Nav_ApproveRole).WithMany().HasForeignKey(t => t.APPROVE_ROLE_ID).OnDelete(DeleteBehavior.Restrict);
            builder.Ignore(t => t.TEAM_ID);
            builder.Ignore(t => t.Tenant);
        }
    }
}
