using System;
using Abp.BackgroundJobs;
using Abp.Dependency;
using Abp.Domain.Repositories;
using YGNT.QuestionLibrary.Core.Tasks.Domain.Dto;

namespace YGNT.QuestionLibrary.Core.Tasks.Domain.Jobs
{
    /// <summary>
    /// 试卷生成任务
    /// </summary>
    public class PaperProduceTaskJob : BackgroundJob<Tuple<long, PaperProduceDto>>, ITransientDependency
    {
        private readonly IRepository<PaperProduceTask, long> _taskRepository;
        private readonly IPaperProduceManager _paperProduceTaskManager;

        public PaperProduceTaskJob(IRepository<PaperProduceTask, long> taskRepository, IPaperProduceManager paperProduceTaskManager)
        {
            _taskRepository = taskRepository;
            _paperProduceTaskManager = paperProduceTaskManager;
        }

        /// <summary>
        /// 进行试卷生成
        /// </summary>
        /// <param name="args">任务id</param>
        public override void Execute(Tuple<long, PaperProduceDto> args)
        {
            var id = args.Item1;
            var pram = args.Item2;
            var task = _taskRepository.Get(id);
            if (task != null)
                _paperProduceTaskManager.Produce(task, pram);
        }
    }
}