Common/UserInterface/
ShowMessage.rs

1// File: Common/Source/UserInterface/ShowMessage.rs
2// Role: Defines the `ShowMessage` ActionEffect.
3// Responsibilities:
4//   - Provide a declarative effect for displaying a modal message to the user.
5//   - This effect abstracts the "what" (show a message) from the "how" (the
6//     UserInterfaceProvider implementation).
7
8//! # ShowMessage Effect
9//!
10//! Defines the `ActionEffect` for displaying a modal message to the user.
11
12use std::sync::Arc;
13
14use serde_json::Value;
15
16use super::{DTO::MessageSeverity::MessageSeverity, UserInterfaceProvider::UserInterfaceProvider};
17use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
18
19/// Creates an effect that, when executed, will display a message to the user
20/// with a given severity and a set of optional action buttons.
21///
22/// It uses the `UserInterfaceProvider` capability from the environment to
23/// perform the operation, which typically involves sending an event to the
24/// frontend and waiting for the user's interaction.
25///
26/// # Parameters
27/// * `Severity`: The `MessageSeverity` of the message (Info, Warning, Error).
28/// * `Message`: The primary text content of the message.
29/// * `OptionsValue`: A `serde_json::Value` representing the
30///   `MessageOptionsDTO`, which can include a title, detail text, and a list of
31///   action buttons.
32///
33/// # Returns
34/// An `ActionEffect` that resolves with an `Option<String>`, containing the
35/// string title of the action button the user clicked, or `None` if the
36/// message was dismissed without an action.
37pub fn ShowMessage(
38	Severity:MessageSeverity,
39
40	Message:String,
41
42	OptionsValue:Value,
43) -> ActionEffect<Arc<dyn UserInterfaceProvider>, CommonError, Option<String>> {
44	ActionEffect::New(Arc::new(move |Provider:Arc<dyn UserInterfaceProvider>| {
45		let MessageClone = Message.clone();
46
47		let OptionsClone = OptionsValue.clone();
48
49		Box::pin(async move { Provider.ShowMessage(Severity, MessageClone, Some(OptionsClone)).await })
50	}))
51}