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

namespace Managing.Application.Trading;

public class GetTradeCommandHandler : IRequestHandler<GetTradeCommand, Trade>
{
    private readonly IExchangeService _exchangeService;
    private readonly IAccountService _accountService;
    public GetTradeCommandHandler(IExchangeService exchangeService, IAccountService accountService)
    {
        _exchangeService = exchangeService;
        _accountService = accountService;
    }

    public Task<Trade> Handle(GetTradeCommand request, CancellationToken cancellationToken)
    {
        var account = _accountService.GetAccount(request.AccountName, true, false).Result;
        return _exchangeService.GetTrade(account, request.ExchangeOrderId, request.Ticker);
    }
}
