using IRaCIS.Core.Domain.Models;
using Microsoft.EntityFrameworkCore.Metadata.Builders;


namespace IRaCIS.Core.Infra.EFCore.EntityConfigration
{
    public class VisitTaskConfigration : IEntityTypeConfiguration<VisitTask>
    {


        public void Configure(EntityTypeBuilder<VisitTask> builder)
        {
            //对于裁判任务而言，一个裁判任务，关联了两个产生裁判的任务
            builder.HasMany(t => t.JudgeVisitList).WithOne(t => t.JudgeVisitTask).HasForeignKey(t => t.JudgeVisitTaskId);

            //对于退回或者重阅的任务而已，会关联多个影响的任务
            builder.HasMany(t => t.TaskInfluenceList).WithOne(s => s.OriginalTask).HasForeignKey(t => t.OriginalTaskId);

            //对于全局任务而言，会关联多个全局访视阅片结果（因为同一全局会对多个访视的结果进行修改）
            builder.HasMany(t => t.GlobalVisitResultList).WithOne(s => s.GlobalVisitTask).HasForeignKey(t => t.GlobalTaskId);
            //对于全局修改的任务而言，会关联多个全局访视阅片结果（因为同一个访视结果，会被多个全局修改）

            //subject 删除了，但是任务没删除，导致的查询问题
            builder.HasQueryFilter(b => b.Subject.IsDeleted == false);


            builder.HasMany(t => t.LesionList).WithOne(s => s.VisitTask).HasForeignKey(t => t.VisitTaskId);

            //肿瘤学任务存在重阅
            builder.HasMany(t => t.OncologyResultList).WithOne(s => s.OncologyVisitTask).HasForeignKey(t => t.OncologyTaskId);


        }
    }
    public class ReadingQuestionTrialConfigration : IEntityTypeConfiguration<ReadingQuestionTrial>
    {
        public void Configure(EntityTypeBuilder<ReadingQuestionTrial> builder)
        {
            //不影响之前的逻辑，附加评估
            builder.HasQueryFilter(p => p.IsAdditional == false);

        }
    }

    

}
