using System.Text.Json; using HermesSocketLibrary.Requests.Messages; using Serilog; using TwitchChatTTS.Chat.Groups; namespace TwitchChatTTS.Hermes.Socket.Requests { public class CreateGroupAck : IRequestAck { public string Name => "create_group"; private readonly IChatterGroupManager _groups; private readonly JsonSerializerOptions _options; private readonly ILogger _logger; public CreateGroupAck(IChatterGroupManager groups, JsonSerializerOptions options, ILogger logger) { _groups = groups; _options = options; _logger = logger; } public void Acknowledge(string requestId, string? json, IDictionary? requestData) { if (string.IsNullOrWhiteSpace(json)) { _logger.Warning($"Group JSON data is null."); return; } var group = JsonSerializer.Deserialize(json, _options); if (group == null) { _logger.Warning($"Group data is null."); return; } var exists = _groups.Get(group.Id); if (exists != null) { _logger.Warning($"Group id already exists [group id: {exists.Id}][group name: {exists.Name} / {group.Name}][group priority: {exists.Priority} / {group.Priority}]"); return; } _logger.Debug($"Adding group [group id: {group.Id}][group name: {group.Name}][group priority: {group.Priority}]"); _groups.Add(group); _logger.Information($"Group has been created [group id: {group.Id}]"); } } }