using Managing.Application.Abstractions;
using Managing.Application.Abstractions.Services;
using Managing.Application.ManageBot.Commands;
using Managing.Domain.Bots;
using MediatR;

namespace Managing.Application.ManageBot
{
    public class GetUserStrategiesCommandHandler : IRequestHandler<GetUserStrategiesCommand, IEnumerable<Bot>>
    {
        private readonly IBotService _botService;
        private readonly IUserService _userService;

        public GetUserStrategiesCommandHandler(IBotService botService, IUserService userService)
        {
            _botService = botService;
            _userService = userService;
        }

        public async Task<IEnumerable<Bot>> Handle(GetUserStrategiesCommand request, CancellationToken cancellationToken)
        {
            var user = await _userService.GetUserByAgentName(request.AgentName);
            return await _botService.GetBotsByUser(user.Id);
        }
    }
}