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

namespace Managing.Application.ManageBot
{
    public class GetUserStrategiesCommandHandler : IRequestHandler<GetUserStrategiesCommand, List<ITradingBot>>
    {
        private readonly IBotService _botService;

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

        public Task<List<ITradingBot>> Handle(GetUserStrategiesCommand request, CancellationToken cancellationToken)
        {
            var allActiveBots = _botService.GetActiveBots();
            var userBots = allActiveBots
                .Where(bot => bot.User != null && bot.User.Name == request.UserName)
                .ToList();

            return Task.FromResult(userBots);
        }
    }
}