using Managing.Application.Abstractions;
using Managing.Application.Abstractions.Services;
using Managing.Application.ManageBot.Commands;
using Managing.Domain.Bots;
using MediatR;
namespace Managing.Application.ManageBot
{
///
/// Handler for retrieving a specific strategy owned by a user
///
public class GetUserStrategyCommandHandler : IRequestHandler
{
private readonly IBotService _botService;
private readonly IUserService _userService;
public GetUserStrategyCommandHandler(IBotService botService, IUserService userService)
{
_botService = botService;
_userService = userService;
}
public async Task Handle(GetUserStrategyCommand request, CancellationToken cancellationToken)
{
var user = await _userService.GetUserByAgentName(request.AgentName);
if (user == null)
{
throw new Exception($"User with agent name {request.AgentName} not found");
}
var strategy = await _botService.GetBotByUserIdAndNameAsync(user.Id, request.StrategyName);
if (strategy == null)
{
throw new Exception($"Strategy with name {request.StrategyName} not found for agent {request.AgentName}");
}
return strategy;
}
}
}