using DigitalData.Core.Contracts.Application; using System.Text.Json.Serialization; namespace DigitalData.Core.Application { /// /// Represents the outcome of a service operation, encapsulating the success or failure status, /// and any associated messages. It also supports optional translation of message keys for localization purposes. /// public class ServiceMessage : IServiceMessage { /// /// Initializes a new instance of the ServiceMessage class. /// public ServiceMessage() { } /// /// Initializes a new instance of the ServiceMessage class, specifying the success status. /// Optionally, a function for translating message keys can be provided. /// If a translation function is provided, it will be used for both string and enum message keys. /// /// Indicates whether the service operation was successful. /// If provided, it will also be adapted for translating enum keys by converting them to strings first. [Obsolete("Deprecated: initialize objects using object initializer.")] public ServiceMessage(bool isSuccess) { IsSuccess = isSuccess; } /// /// Initializes a new instance of the ServiceMessage class with specified success status, and messages. /// /// Indicates whether the service operation was successful. /// An array of messages related to the operation's outcome. [Obsolete("Deprecated: initialize objects using object initializer.")] public ServiceMessage(bool isSuccess, params string[] messages) { IsSuccess = isSuccess; Messages = messages.ToList(); } /// /// Gets or sets a value indicating whether the service operation was successful. /// public bool IsSuccess { get; set; } = false; /// /// Represents the list of flags that indicate specific types of statuses or conditions in a service operation. /// These flags help in categorizing the state of the operation more granularly, allowing for multiple conditions to be represented simultaneously. /// [JsonIgnore] public ICollection Flags { get; } = new List(); /// /// Checks if any of the current service message's flags matches the specified flag based on their string representations. /// This method is useful for conditional logic where the exact string representation of the flag values is crucial. /// /// The flag to check against the current service message's flags. /// true if a flag with a matching string representation exists; otherwise, false. public bool HasFlag(Enum flag) => Flags.Any(f => f.ToString() == flag.ToString()); /// /// [Obsolete("Deprecated: Use ClientMessages instead.")] /// Gets a collection of messages associated with the service operation. These messages can be error descriptions, /// success notifications, or other relevant information related to the operation's outcome. /// [Obsolete("Deprecated: Use ClientMessages instead.")] public ICollection Messages { get; init; } = new List(); /// /// Gets a collection of messages intended for client display. This replaces the deprecated 'Messages' property. /// public ICollection ClientMessages { get; init; } = new List(); /// /// Gets a collection of messages used for tracing program execution at a fine-grained level. These are typically voluminous and detailed. /// [JsonIgnore] public ICollection TraceMessages { get; init; } = new List(); /// /// Gets a collection of messages helpful for debugging during development. These messages are often diagnostic. /// [JsonIgnore] public ICollection DebugMessages { get; init; } = new List(); /// /// Gets a collection of informational messages, less critical than warnings, generally used for non-critical notifications. /// [JsonIgnore] public ICollection InformationMessages { get; init; } = new List(); /// /// Gets a collection of messages indicating potential issues that are not necessarily errors, but which may require attention. /// [JsonIgnore] public ICollection WarningMessages { get; init; } = new List(); /// /// Gets a collection of error messages indicating failures or problems within the service. /// [JsonIgnore] public ICollection ErrorMessages { get; init; } = new List(); /// /// Gets a collection of messages indicating critical issues that require immediate attention. /// [JsonIgnore] public ICollection CriticalMessages { get; init; } = new List(); /// /// Adds a new message to the collection of messages associated with the service operation. /// /// The message to add. /// The current instance of ServiceMessage, allowing for method chaining. [Obsolete("Deprecated: Use ClientMessages instead.")] public IServiceMessage WithMessage(string message) { Messages.Add(message); return this; } /// /// Adds a message corresponding to the specified message key to the collection of messages associated with the service operation. /// This method uses the string representation of the enum value as the message. /// /// The enum value representing the message key. /// The current instance of ServiceMessage, allowing for method chaining. [Obsolete("Deprecated: Use ClientMessages instead.")] public IServiceMessage WithMessageKey(Enum messageKey) { Messages.Add(messageKey.ToString()); return this; } } }