using Serilog; namespace TwitchChatTTS.Hermes.Socket.Requests { public class RequestAckManager { private readonly IDictionary _acknowledgements; private readonly ILogger _logger; public RequestAckManager(IEnumerable acks, ILogger logger) { _acknowledgements = acks.ToDictionary(a => a.Name, a => a); _logger = logger; } public void Fulfill(string type, string requestId, string data, IDictionary? requestData) { if (!_acknowledgements.TryGetValue(type, out var ack)) { _logger.Warning($"Found unknown request type when acknowledging [type: {type}]"); return; } _logger.Debug($"Request acknowledgement found [type: {type}][data: {data}]"); try { ack.Acknowledge(requestId, data, requestData); _logger.Debug($"Request acknowledged without error [type: {type}][data: {data}]"); } catch (Exception ex) { _logger.Error(ex, "Failed to fulfill a request ackowledgement."); } } } }