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

namespace Managing.Application.Trading.Handlers;

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 async Task<Trade> Handle(GetTradeCommand request, CancellationToken cancellationToken)
    {
        var account = await _accountService.GetAccount(request.AccountName, true, false);
        return await _exchangeService.GetTrade(account, request.ExchangeOrderId, request.Ticker);
    }
}
