using DigitalData.Core.Contracts.Application; namespace DigitalData.Core.Application { /// /// Provides extension methods for IServiceMessage to enhance the usability of service messages /// by allowing easy addition of various types of messages including client, trace, debug, information, /// warning, error, and critical messages. These methods support both direct messages and enum-based keys /// for messages, facilitating localized or custom-formatted messages. /// public static class ServiceMessageExtensions { #region ClientMessage /// /// Adds a single client message to the service message. /// /// The service message to modify. /// The message to add. /// The modified service message instance. public static T WithClientMessage(this T serviceMessage, string message) where T : IServiceMessage { serviceMessage.ClientMessages.Add(message); return serviceMessage; } /// /// Adds a client message based on an enumeration key to the service message. /// /// The service message to modify. /// The enum key representing the message. /// The modified service message instance. public static T WithClientMessageKey(this T serviceMessage, Enum messageKey) where T : IServiceMessage { var message = serviceMessage.KeyTranslator(messageKey.ToString()); return serviceMessage.WithClientMessage(message); } #endregion #region TraceMessages /// /// Adds a trace message to the service message. /// /// The service message to modify. /// The trace message to add. /// The modified service message instance. public static T WithTraceMessage(this T serviceMessage, string message) where T : IServiceMessage { serviceMessage.TraceMessages.Add(message); return serviceMessage; } /// /// Adds a trace message based on an enumeration key to the service message. /// /// The service message to modify. /// The enum key representing the trace message. /// The modified service message instance. public static T WithTraceMessageKey(this T serviceMessage, Enum messageKey) where T : IServiceMessage { var message = serviceMessage.KeyTranslator(messageKey.ToString()); return serviceMessage.WithTraceMessage(message); } #endregion #region DebugMessages /// /// Adds a debug message to the service message. /// /// The service message to modify. /// The debug message to add. /// The modified service message instance. public static T WithDebugMessage(this T serviceMessage, string message) where T : IServiceMessage { serviceMessage.DebugMessages.Add(message); return serviceMessage; } /// /// Adds a debug message based on an enumeration key to the service message. /// /// The service message to modify. /// The enum key representing the debug message. /// The modified service message instance. public static T WithDebugMessageKey(this T serviceMessage, Enum messageKey) where T : IServiceMessage { var message = serviceMessage.KeyTranslator(messageKey.ToString()); return serviceMessage.WithDebugMessage(message); } #endregion #region WarningMessages /// /// Adds a warning message to the service message. /// /// The service message to modify. /// The warning message to add. /// The modified service message instance. public static T WithWarningMessage(this T serviceMessage, string message) where T : IServiceMessage { serviceMessage.WarningMessages.Add(message); return serviceMessage; } /// /// Adds a warning message based on an enumeration key to the service message. /// /// The service message to modify. /// The enum key representing the warning message. /// The modified service message instance. public static T WithWarningMessageKey(this T serviceMessage, Enum messageKey) where T : IServiceMessage { var message = serviceMessage.KeyTranslator(messageKey.ToString()); return serviceMessage.WithWarningMessage(message); } #endregion #region ErrorMessages /// /// Adds an error message to the service message. /// /// The service message to modify. /// The error message to add. /// The modified service message instance. public static T WithErrorMessage(this T serviceMessage, string message) where T : IServiceMessage { serviceMessage.ErrorMessages.Add(message); return serviceMessage; } /// /// Adds an error message based on an enumeration key to the service message. /// /// The service message to modify. /// The enum key representing the error message. /// The modified service message instance. public static T WithErrorMessageKey(this T serviceMessage, Enum messageKey) where T : IServiceMessage { var message = serviceMessage.KeyTranslator(messageKey.ToString()); return serviceMessage.WithErrorMessage(message); } #endregion #region CriticalMessages /// /// Adds a critical message to the service message. /// /// The service message to modify. /// The critical message to add. /// The modified service message instance. public static T WithCriticalMessage(this T serviceMessage, string message) where T : IServiceMessage { serviceMessage.CriticalMessages.Add(message); return serviceMessage; } /// /// Adds a critical message based on an enumeration key to the service message. /// /// The service message to modify. /// The enum key representing the critical message. /// The modified service message instance. public static T WithCriticalMessageKey(this T serviceMessage, Enum messageKey) where T : IServiceMessage { var message = serviceMessage.KeyTranslator(messageKey.ToString()); return serviceMessage.WithCriticalMessage(message); } #endregion } }