using EntityFrameworkCore.Triggered;

namespace IRaCIS.Core.Application.Triggers
{
    /// <summary>
    ///   因为可能先一致性核查通过，生成其他标准的任务了，新签名的标准也需要产生任务
    /// </summary>
    public class TrialCriterionSignTrigger(
       IVisitTaskHelpeService _visitTaskHelpeService) : IAfterSaveTrigger<ReadingQuestionCriterionTrial>
    {
        public async Task AfterSave(ITriggerContext<ReadingQuestionCriterionTrial> context, CancellationToken cancellationToken)
        {
            var trialCriterion = context.Entity;


            if (context.ChangeType == ChangeType.Modified)
            {

                // 一致性核查通过  生成读片任务  同时要是自动生成的才会触发
                if (context.UnmodifiedEntity?.ReadingInfoSignTime != trialCriterion.ReadingInfoSignTime && trialCriterion.ReadingInfoSignTime != null && trialCriterion.IsAutoCreate == true)
                {


                    await _visitTaskHelpeService.BaseCritrionGenerateVisitTask(trialCriterion.TrialId, trialCriterion.Id);
                }

            }
        }
    }
}