using System.Text.Json; using HermesSocketLibrary.Requests.Messages; using Serilog; using TwitchChatTTS.Bus; using TwitchChatTTS.Bus.Data; namespace TwitchChatTTS.Hermes.Socket.Requests { public class GetRedeemableActionsAck : IRequestAck { public string Name => "get_redeemable_actions"; private readonly ServiceBusCentral _bus; private readonly JsonSerializerOptions _options; private readonly ILogger _logger; public GetRedeemableActionsAck( ServiceBusCentral bus, JsonSerializerOptions options, ILogger logger) { _bus = bus; _options = options; _logger = logger; } public void Acknowledge(string requestId, string json, IDictionary? requestData) { if (requestData == null) { _logger.Warning("Request data is null."); return; } if (requestData["redemptions"] is not IEnumerable redemptions) { _logger.Warning("Failed to read the redemptions while updating redemption actions."); return; } IEnumerable? actions = JsonSerializer.Deserialize>(json, _options); if (actions == null) { _logger.Warning("Failed to read the redeemable actions for redemptions."); return; } _logger.Information($"Redeemable actions loaded [count: {actions.Count()}]"); _bus.Send(this, "redemptions_initiation", new RedemptionInitiation() { Redemptions = redemptions, Actions = actions.ToDictionary(a => a.Name, a => a) }); } } }