71 lines
3.8 KiB
C#

namespace DigitalData.Core.Contracts.Application
{
/// <summary>
/// Defines the base functionality for a service, including creating service messages and results.
/// </summary>
public interface IServiceBase
{
/// <summary>
/// Creates a service message.
/// </summary>
/// <param name="isSuccess">Indicates if the operation was successful.</param>
/// <param name="messages">The messages associated with the operation.</param>
/// <returns>A service message indicating the outcome of the operation and any associated messages.</returns>
IServiceMessage CreateMessage(bool isSuccess, params string[] messages);
/// <summary>
/// Creates a service result with the specified data.
/// </summary>
/// <typeparam name="T">The type of data the service result will contain.</typeparam>
/// <param name="data">The data for the service result.</param>
/// <param name="isSuccess">Indicates if the operation was successful.</param>
/// <param name="messages">The messages associated with the operation.</param>
/// <returns>A service result containing the data and indicating the outcome of the operation.</returns>
IServiceResult<T> CreateResult<T>(T? data, bool isSuccess, params string[] messages);
/// <summary>
/// Creates a successful service message.
/// </summary>
/// <param name="messages">The success messages.</param>
/// <returns>A successful service message.</returns>
IServiceMessage Successful(params string[] messages);
/// <summary>
/// Creates a failed service message.
/// </summary>
/// <param name="messages">The failure messages.</param>
/// <returns>A failed service message.</returns>
IServiceMessage Failed(params string[] messages);
/// <summary>
/// Creates a successful service result with the specified data.
/// </summary>
/// <typeparam name="T">The type of data the service result will contain.</typeparam>
/// <param name="data">The data to include in the service result.</param>
/// <param name="messages">The success messages.</param>
/// <returns>A successful service result containing the data.</returns>
IServiceResult<T> Successful<T>(T data, params string[] messages);
/// <summary>
/// Creates a failed service result, optionally including data.
/// </summary>
/// <typeparam name="T">The type of data the service result can contain.</typeparam>
/// <param name="data">Optional data to include in the failed service result.</param>
/// <param name="messages">The failure messages.</param>
/// <returns>A failed service result, which may or may not contain data.</returns>
IServiceResult<T> Failed<T>(T? data = default, params string[] messages);
/// <summary>
/// Creates a failed service result without explicitly including data, using only failure messages.
/// </summary>
/// <remarks>
/// This overload is useful when you want to indicate a failure without the need to return any specific data,
/// but still want to provide details about the failure through messages.
/// </remarks>
/// <typeparam name="T">The type of data the service result can contain. The result will contain the default value for this type.</typeparam>
/// <param name="messages">An array of failure messages associated with the operation. These provide detail about why the operation failed.</param>
/// <returns>A failed service result. The data part of the result will be set to the default value for the specified type.</returns>
IServiceResult<T> Failed<T>(params string[] messages);
}
}