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

namespace YGNT.QuestionLibrary.Core.Tasks.Domain.Jobs
{
    public class QuestionConvertTaskJob : BackgroundJob<long>, ITransientDependency
    {
        private readonly IQuestionConvertManager _questionConvertManager;
        private readonly IRepository<QuestionConvertTask, long> _questionConvertTaskRepository;

        public QuestionConvertTaskJob(IQuestionConvertManager questionConvertManager, IRepository<QuestionConvertTask, long> questionConvertTaskRepository)
        {
            _questionConvertManager = questionConvertManager;
            _questionConvertTaskRepository = questionConvertTaskRepository;
        }

        public override void Execute(long args)
        {
            var task = _questionConvertTaskRepository.FirstOrDefault(x => x.Id == args);
            if (task != null)
                _questionConvertManager.ConvertHtmlToDocByTask(task);
        }
    }
}