using Microsoft.EntityFrameworkCore;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using wispro.sp.api.Job;
using wispro.sp.share;

namespace wispro.sp.api.AppealHandler
{
    public class MissingCaseAppealHandler : IDoAppealObject
    {
        

        public void DoAppeal(AppealObject appeal, int appealRecordid, DbContext spContext)
        {
            var trigger = TriggerBuilder.Create()
               .WithDescription("获取案件信息")
               .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).WithRepeatCount(0))
               .Build();

            var job = JobBuilder.Create(typeof(GetPerformanceItemJob))
                .WithIdentity("获取案件任务")
                .Build();

            foreach (var iv in appeal.inputFieldValues)
            {
                if(iv.InputField == null)
                {
                    iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s=>s.Id == iv.InputFieldId);
                }

                if(iv.InputField.FieldName == "我方文号")
                {
                    job.JobDataMap.Put("CaseNo", iv.Value);
                    continue;
                }

                if(iv.InputField.FieldName =="处理事项")
                {
                    job.JobDataMap.Put("DoItem", iv.Value);
                    continue;
                }

                if (iv.InputField.FieldName == "案件阶段")
                {
                    job.JobDataMap.Put("CaseStage", iv.Value);
                    
                    continue;
                }
            }

            _ = QuartzUtil.Add(job, trigger);
        }


    }
}
