using FrameworkDAL.DTO.MessageHub.MessageHubGenerator; using GB5Shared.DTO.Framework.Login; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Threading; using System.Threading.Tasks; namespace FrameworkBLL.MessageHub.MessageHubPlatforms { /// /// Postman Platform /// ---------------- /// ✔ Internal / Debug mode platform /// ✔ Supports Template and Non-Template (Conversation) messages /// ✔ Logs all messages for testing /// public class PostmanPlatform : IMessageHubPlatform.IPostmanPlatform { private readonly ILogger _logger; public PostmanPlatform(ILogger logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } // ========================================================== // ✅ TEMPLATE VERSION (Postman Template Engine) // ========================================================== public Task SendPostmanTemplate( MessageHubDTO dto, LoginDTO login, CancellationToken ct) { if (dto == null) throw new ArgumentNullException(nameof(dto)); if (login == null) throw new ArgumentNullException(nameof(login)); var timestamp = DateTime.UtcNow; _logger.LogInformation("[{Time}] POSTMAN TEMPLATE - MESSAGE", timestamp); _logger.LogInformation("Recipient : {Recipient}", dto.Recipient); _logger.LogInformation("Message : {Message}", dto.MessageText); _logger.LogInformation("Sent By : {UserName} ({UserId})", login.UserName, login.UserId); var responseObject = new { Mode = "Template", Recipient = dto.Recipient, Message = dto.MessageText, SentBy = login.UserName, ClientId = login.ClientId, UserId = login.UserId, Time = timestamp }; _logger.LogInformation( "Postman Template message prepared successfully | Recipient={Recipient} | User={UserName}", dto.Recipient, login.UserName); return Task.FromResult(new MessageHubResponseDTO { Success = true, Message = "Postman Template message processed successfully", ResponseData = JsonConvert.SerializeObject(responseObject) }); } // ========================================================== // ✅ NON-TEMPLATE VERSION (Postman Conversation Engine) // ========================================================== public Task SendPostmanConversation( MessageHubDTO dto, LoginDTO login, CancellationToken ct) { if (dto == null) throw new ArgumentNullException(nameof(dto)); if (login == null) throw new ArgumentNullException(nameof(login)); var timestamp = DateTime.UtcNow; _logger.LogInformation("[{Time}] POSTMAN CONVERSATION - MESSAGE", timestamp); _logger.LogInformation("Recipient : {Recipient}", dto.Recipient); _logger.LogInformation("Message : {Message}", dto.MessageText); _logger.LogInformation("Sent By : {UserName} ({UserId})", login.UserName, login.UserId); var responseObject = new { Mode = "NonTemplate", Recipient = dto.Recipient, Message = dto.MessageText, SentBy = login.UserName, ClientId = login.ClientId, UserId = login.UserId, Time = timestamp }; _logger.LogInformation( "Postman Conversation message prepared successfully | Recipient={Recipient} | User={UserName}", dto.Recipient, login.UserName); return Task.FromResult(new MessageHubResponseDTO { Success = true, Message = "Postman Conversation message processed successfully", ResponseData = JsonConvert.SerializeObject(responseObject) }); } } }