using Abp.BackgroundJobs;
using Abp.Dependency;
using Abp.Domain.Repositories;

namespace YGNT.QuestionLibrary.Core.Tasks.Domain.Jobs
{
    /// <summary>
    /// 试题解析任务
    /// </summary>
    public class QuestionResolveTaskJob : BackgroundJob<long>, ITransientDependency
    {
        private readonly IRepository<QuestionResolveTask, long> _questionResolveTaskRepository;
        private readonly IQuestionResolveManager _questionResolveTaskManager;

        public QuestionResolveTaskJob(IRepository<QuestionResolveTask, long> questionResolveTaskRepository, IQuestionResolveManager questionResolveTaskManager)
        {
            _questionResolveTaskRepository = questionResolveTaskRepository;
            _questionResolveTaskManager = questionResolveTaskManager;
        }

        /// <summary>
        /// 进行试题解析
        /// </summary>
        /// <param name="args"></param>
        public override void Execute(long args)
        {
            var resolveTask = _questionResolveTaskRepository.FirstOrDefault(x => x.Id == args);
            if (resolveTask == null) return;
            _questionResolveTaskManager.Resolve(resolveTask);
        }
    }
}