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

namespace Managing.Application.ManageBot
{
    /// <summary>
    /// Handler for retrieving a specific strategy owned by a user
    /// </summary>
    public class GetUserStrategyCommandHandler : IRequestHandler<GetUserStrategyCommand, Bot>
    {
        private readonly IBotService _botService;

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

        public async Task<Bot> Handle(GetUserStrategyCommand request, CancellationToken cancellationToken)
        {
            var strategy = await _botService.GetBotByName(request.StrategyName);
            if (strategy == null)
            {
                throw new Exception($"Strategy with name {request.StrategyName} not found");
            }
            return strategy;
        }
    }
}