using Serilog;

namespace CortexMediatorDemo.API.Services;

/// <summary>
/// Defines a service responsible for sending notifications.
/// This service can be used to send different types of notifications
/// within the application's processes.
/// </summary>
public interface INotificationService
{
    /// <summary>
    /// Sends a notification message, with an optional flag indicating if it is an error.
    /// If the message is flagged as an error, it will be logged as an error; otherwise, it will be logged as information.
    /// </summary>
    /// <param name="message">The notification message to be sent.</param>
    /// <param name="isError">A flag indicating whether the notification is an error. Default is false.</param>
    /// <returns>A Task representing the asynchronous operation.</returns>
    Task SendNotification(string message, bool isError = false);
}

/// <summary>
/// Implements the INotificationService interface to provide functionality
/// for sending notifications within the application's processes.
/// This service logs notification messages with varying severity levels
/// based on the nature of the notification (e.g., error or informational).
/// </summary>
public class NotificationService : INotificationService
{
    /// <summary>
    /// Sends a notification with a message and an optional flag to indicate its severity.
    /// If the notification is flagged as an error, it logs the message as an error; otherwise, it logs it as informational.
    /// </summary>
    /// <param name="message">The message content to include in the notification.</param>
    /// <param name="isError">Optional flag to specify if the notification is an error. Default is false.</param>
    /// <returns>A Task representing the asynchronous operation of sending the notification.</returns>
    public async Task SendNotification(string message, bool isError = false)
    {
        if (isError)
        {
            Log.Error("##Notification Service: {Message} with error", message);
        }
        else
        {
            Log.Information("##Notification Service: {Message}", message);
        }
    }
}