using Diligent.WebAPI.Business.Interfaces;
using Diligent.WebAPI.Host.Mediator.Notifications.Commands;
using MediatR;

namespace Diligent.WebAPI.Host.Mediator.Notifications.Handlers
{
    public class DeleteNotificationHandler : IRequestHandler<DeleteNotificationCommand, Unit>
    {
        private readonly ICustomerService _customerService;

        public DeleteNotificationHandler(ICustomerService customerService)
        {
            _customerService = customerService;
        }

        public async Task<Unit> Handle(DeleteNotificationCommand request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new BadHttpRequestException("Object cannot be null");
            }

            var result = await _customerService.DeleteNotification(request.NotificationData.UserId, request.NotificationData.RoomId);

            if (!result)
            {
                throw new Exception("Problem with deleting notification");
            }

            return new Unit();
        }
    }
}
