using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.CultureServices;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace DigitalData.Core.Application
{
public class ResponseService : IResponseService
{
protected readonly IKeyTranslationService _translationService;
public ResponseService(IKeyTranslationService translationService)
{
_translationService = translationService;
}
#region WITHOUT_MESSAGE
///
/// Creates a service message indicating success or failure without additional messages.
///
/// Indicates if the operation was successful.
/// A service message reflecting the operation outcome.
public IServiceMessage CreateMessage(bool isSuccess = false) => new ServiceMessage()
{
IsSuccess = isSuccess,
KeyTranslator = _translationService.Translate
};
///
/// Creates a service result containing the provided data and a success flag, without additional messages.
///
/// The type of the data included in the result.
/// The data to include in the result.
/// Indicates if the operation was successful.
/// A service result with the specified data and outcome.
public IServiceResult CreateResult(T? data = default, bool isSuccess = false) => new ServiceResult()
{
IsSuccess = isSuccess,
Data = data,
KeyTranslator = _translationService.Translate
};
///
/// Creates a service message indicating a successful operation without additional messages.
///
/// A service message indicating a successful operation.
public IServiceMessage Successful() => CreateMessage(true);
///
/// Creates a service message indicating a failed operation without additional messages.
///
/// A service message indicating a failed operation.
public IServiceMessage Failed() => CreateMessage(false);
///
/// Creates a successful service result with the specified data, without additional messages.
///
/// The type of data included in the result.
/// The data to include in the result.
/// A successful service result containing the specified data.
public IServiceResult Successful(T data) => CreateResult(data, true);
///
/// Creates a failed service result with optional data, without additional messages.
///
/// The type of data the service result can contain.
/// Optional data to include in the result.
/// A failed service result, which may or may not contain the specified data.
public IServiceResult Failed(T? data = default) => CreateResult(data, false);
#endregion
#region WITH_STRING_MESSAGE
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a service message with the specified success flag and messages.
///
/// Indicates if the operation was successful.
/// An array of messages associated with the operation.
/// A new instance of reflecting the operation outcome.
public virtual IServiceMessage CreateMessage(bool isSuccess, params string[] messages) => new ServiceMessage(isSuccess, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a service result containing the provided data, success flag, and messages.
///
/// The type of the data included in the result.
/// The data to include in the result.
/// Indicates if the operation was successful.
/// An array of messages associated with the operation.
/// A new instance of with the specified data and outcome.
public virtual IServiceResult CreateResult(T? data = default, bool isSuccess = true, params string[] messages) => new ServiceResult(data, isSuccess, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a successful service message.
///
/// An array of success messages.
/// A successful service message.
public virtual IServiceMessage Successful(params string[] messages) => CreateMessage(true, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a failed service message.
///
/// An array of failure messages.
/// A failed service message.
public virtual IServiceMessage Failed(params string[] messages) => CreateMessage(false, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a successful service result with the provided data.
///
/// The type of data included in the result.
/// The data to include in the result.
/// An array of success messages.
/// A successful service result containing the specified data.
public virtual IServiceResult Successful(T data, params string[] messages) => CreateResult(data, true, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a failed service result, optionally including data.
///
/// The type of data the service result can contain.
/// Optional data to include in the failed result.
/// An array of failure messages.
/// A failed service result, which may or may not contain the specified data.
public virtual IServiceResult Failed(T? data = default, params string[] messages) => CreateResult(data, false, messages);
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a failed service result using only failure messages, without explicitly including data.
///
///
/// This method provides a convenient way to create a failed service result when the failure does not pertain to any specific data,
/// or when the inclusion of data is not necessary to convey the failure reason. The data part of the result will be set to its default value.
///
/// The type of data the service result can contain. The result will contain the default value for this type.
/// An array of failure messages that provide details about the reasons for the operation's failure.
/// A failed service result. The data part of the result will be set to the default value for the specified type,
/// and it will include the provided failure messages.
public virtual IServiceResult Failed(params string[] messages) => Failed(default, messages);
#endregion
#region WITH_ENUM_MESSAGE
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a service message with the specified success flag and enumeration messages.
///
/// Indicates if the operation was successful.
/// An array of enumeration values associated with the operation.
/// A new instance of reflecting the operation outcome with enumeration messages.
public IServiceMessage CreateMessage(bool isSuccess, params Enum[] messages) => CreateMessage(isSuccess, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a service result containing the provided data, success flag, and enumeration messages.
///
/// The type of the data included in the result.
/// The data to include in the result.
/// Indicates if the operation was successful.
/// An array of enumeration values associated with the operation.
/// A new instance of with the specified data and outcome using enumeration messages.
public IServiceResult CreateResult(T? data, bool isSuccess, params Enum[] messages) => CreateResult(data, isSuccess, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a successful service message using enumeration messages.
///
/// An array of success enumeration values.
/// A successful service message.
public IServiceMessage Successful(params Enum[] messages) => CreateMessage(true, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a failed service message using enumeration messages.
///
/// An array of failure enumeration values.
/// A failed service message.
public IServiceMessage Failed(params Enum[] messages) => CreateMessage(false, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a successful service result with the provided data using enumeration messages.
///
/// The type of data included in the result.
/// The data to include in the result.
/// An array of success enumeration values.
/// A successful service result containing the specified data.
public IServiceResult Successful(T data, params Enum[] messages) => CreateResult(data, true, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a failed service result, optionally including data, using enumeration messages.
///
/// The type of data the service result can contain.
/// Optional data to include in the failed result.
/// An array of failure enumeration values.
/// A failed service result, which may or may not contain the specified data.
public IServiceResult Failed(T? data = default, params Enum[] messages) => CreateResult(data, false, messages.Select(m => m.ToString()).ToArray());
[Obsolete("Deprecated: Use ClientMessages instead.")]
///
/// Creates a failed service result using only failure messages, without explicitly including data.
///
/// The type of data the service result can contain. The result will contain the default value for this type.
/// An array of failure enumeration values that provide details about the reasons for the operation's failure.
/// A failed service result. The data part of the result will be set to the default value for the specified type,
/// and it will include the provided failure messages.
public IServiceResult Failed(params Enum[] messages) => Failed(default(T), messages);
#endregion
}
}