using Tiobon.Core.Common;
using Tiobon.Core.EventBus.EventHandling;
using Tiobon.Core.IServices;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace Tiobon.Core.EventBus
{
    public class TiobonQueryIntegrationEventHandler : IIntegrationEventHandler<TiobonQueryIntegrationEvent>
    {
        private readonly ITiobonArticleServices _TiobonArticleServices;
        private readonly ILogger<TiobonQueryIntegrationEventHandler> _logger;

        public TiobonQueryIntegrationEventHandler(
            ITiobonArticleServices TiobonArticleServices,
            ILogger<TiobonQueryIntegrationEventHandler> logger)
        {
            _TiobonArticleServices = TiobonArticleServices;
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }

        public async Task Handle(TiobonQueryIntegrationEvent @event)
        {
            _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, "Tiobon.Core", @event);

            ConsoleHelper.WriteSuccessLine($"----- Handling integration event: {@event.Id} at Tiobon.Core - ({@event})");

            await _TiobonArticleServices.QueryById(@event.TiobonId.ToString());
        }

    }
}
