using DigitalData.Core.Contracts.Infrastructure;
namespace DigitalData.Core.Contracts.Application
{
///
/// Defines the contract for CRUD operations at the service level using Data Transfer Objects (DTOs) for entities of type TEntity,
/// wrapped in an IServiceResult to encapsulate the outcome of the operation, including success, data, and error messages.
///
/// The repository type that provides CRUD operations for entities of type TEntity.
/// The type of the Data Transfer Object this service works with to create new entity.
/// The type of the Data Transfer Object this service works with to read new entity.
/// The type of the Data Transfer Object this service works with to update new entity.
/// The type of the entity this service maps to.
/// The type of the identifier for the entity.
public interface ICRUDService : IServiceBase
where TCRUDRepository : ICRUDRepository where TCreateDto : class where TReadDto : class where TUpdateDto : class where TEntity : class
{
///
/// Creates a new entity based on the provided DTO and returns the result wrapped in an IServiceResult,
/// including the created entity on success or an error message on failure.
///
/// The createDto to create a new entity from.
/// An IServiceResult containing the id of created entity or an error message.
Task> CreateAsync(TCreateDto createDto);
///
/// Retrieves an entity by its identifier and returns its readDTO representation wrapped in an IServiceResult,
/// including the readDTO on success or null and an error message on failure.
///
/// The identifier of the entity to retrieve.
/// An IServiceResult containing the readDTO representing the found entity or null, with an appropriate message.
Task> ReadByIdAsync(TId id);
///
/// Retrieves all entities and returns their readDTO representations wrapped in an IServiceResult,
/// including a collection of readDTOs on success or an error message on failure.
///
/// An IServiceResult containing a collection of readDTOs representing all entities or an error message.
Task>> ReadAllAsync();
///
/// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage,
/// indicating the success or failure of the operation, including the error messages on failure.
///
/// The updateDTO with updated values for the entity.
/// An IServiceMessage indicating the outcome of the update operation, with an appropriate message.
Task UpdateAsync(TUpdateDto updateDto);
///
/// Deletes an entity by its identifier and returns the result wrapped in an IServiceMessage,
/// indicating the success or failure of the operation, including the error messages on failure.
///
/// The identifier of the entity to delete.
/// An IServiceMessage indicating the outcome of the delete operation, with an appropriate message.
Task DeleteAsyncById(TId id);
///
/// Asynchronously checks if an entity with the specified identifier exists within the data store.
///
/// The identifier of the entity to check.
/// A task that represents the asynchronous operation. The task result contains a boolean value indicating whether the entity exists.
Task HasEntity(TId id);
///
/// Handles exceptions that occur within service actions. This method should log the exception
/// and return an String that contains information about the error, which can then be sent to the client.
/// The implementation should determine the appropriate level of detail to include in the error message
/// based on security and usability considerations.
///
/// The exception that occurred during the controller action.
/// An string instance representing the outcome of the error handling process.
/// This includes a flag indicating the operation was unsuccessful and any relevant error messages.
string HandleException(Exception ex);
}
}