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

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

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

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

        return new Response(cached);
    }
}