using Application.Abstractions.Messaging;
using Application.Abstractions.Cache;

namespace Application.Features.Api.Crypto.Trade.GetLive;

public sealed class Handler(ICacheService cache) : IQueryHandler<Query, Response>
{
    public async Task<Response> Handle(Query request, CancellationToken ct)
    {
        var cacheKey = CacheKeys.CryptoTradeLive(request.Market);

        var cached = await cache.GetAsync<Response.TradeItem>(cacheKey, ct);

        return new Response(cached);
    }
}