using DigitalData.Core.Contracts.Application;
namespace DigitalData.Core.Application
{
///
/// Represents the outcome of a service operation, encapsulating the success or failure status,
/// and any associated messages.
///
public class ServiceMessage : IServiceMessage
{
///
/// Initializes a new instance of the ServiceMessage class with specified success status, and messages.
///
/// Indicates whether the service operation was successful.
/// The data associated with a successful operation.
/// An array of messages related to the operation's outcome.
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; }
///
/// Gets or sets a collection of messages associated with the service operation.
///
public List Messages { get; set; } = 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.
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.
public IServiceMessage WithMessageKey(Enum messageKey)
{
Messages.Add(messageKey.ToString());
return this;
}
}
}