using Diligent.WebAPI.Business.Interfaces;
using Diligent.WebAPI.Business.Services;
using Diligent.WebAPI.Host.Mediator.Rooms.Commands;
using MediatR;

namespace Diligent.WebAPI.Host.Mediator.Chat.Handlers
{
    public class CreateRoomHandler : IRequestHandler<CreateRoomCommand, Unit>
    {
        private readonly IRoomRepository _roomRepository;

        public CreateRoomHandler(IRoomRepository roomRepository)
        {
            _roomRepository = roomRepository;
        }
        public async Task<Unit> Handle(CreateRoomCommand request, CancellationToken cancellationToken)
        {
            if (request.Room == null)
            {
                throw new BadHttpRequestException("Room can't be null");
            }

            await _roomRepository.CreateAsync(request.Room);

            return new Unit();
        }
    }
}
