using Managing.Application.Abstractions.Services;
using Managing.Application.Trading.Commands;
using Managing.Domain.Trades;
using MediatR;

namespace Managing.Application.Trading.Handlers
{
    public class GetTradesCommandHandler : IRequestHandler<GetTradesCommand, List<Trade>>
    {
        private readonly IExchangeService _exchangeService;
        private readonly IAccountService _accountService;

        public GetTradesCommandHandler(IExchangeService exchangeService, IAccountService accountService)
        {
            _exchangeService = exchangeService;
            _accountService = accountService;
        }

        public async Task<List<Trade>> Handle(GetTradesCommand request, CancellationToken cancellationToken)
        {
            var account = await _accountService.GetAccount(request.AccountName, true, false);
            return await _exchangeService.GetTrades(account, request.Ticker);
        }
    }
}
