using Bp.Sync.BackEnd.Infrastructure.Repositories.Systems;
using Bp.Sync.Domain.Elastics.Systems;
using Bp.Sync.Dto.Results;
using MediatR;
using Newtonsoft.Json;
using System.Threading;
using System.Threading.Tasks;

namespace Bp.Sync.BackEnd.Application.Commands.Systems.Histories
{
    public class AddHistoryElasticHandler : IRequestHandler<AddHistoryElasticCommand, BaseResult>
    {
        private readonly IHistoryElasticRepository _historyElasticRepository;
        public AddHistoryElasticHandler(IHistoryElasticRepository historyElasticRepository)
        {
            _historyElasticRepository = historyElasticRepository;
        }
        public async Task<BaseResult> Handle(AddHistoryElasticCommand request, CancellationToken cancellationToken)
        {
            HistoryElastic list = JsonConvert.DeserializeObject<HistoryElastic>(request.HistoryElastics);

            return await _historyElasticRepository.Add(list);
        }
    }
}
