using Managing.Application.Abstractions;
using Managing.Application.ManageBot.Commands;
using MediatR;

namespace Managing.Application.ManageBot
{
    public class ToggleIsForWatchingCommandHandler : IRequestHandler<ToggleIsForWatchingCommand, string>
    {
        private readonly IBotService _botService;

        public ToggleIsForWatchingCommandHandler(IBotService botService)
        {
            _botService = botService;
        }

        public Task<string> Handle(ToggleIsForWatchingCommand request, CancellationToken cancellationToken)
        {
            _botService.ToggleIsForWatchingOnly(request.Name);
            var bot = _botService.GetActiveBots().FirstOrDefault(b => b.Name == request.Name);
            return Task.FromResult(bot?.IsForWatchingOnly.ToString());
        }
    }
}