use serde_json::Value;
use url::Url;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum ActionType {
View,
Broadcast,
Http,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Action {
pub action: ActionType,
pub label: String,
pub url: Url,
pub clear: Option<bool>,
pub body: Option<Value>,
}
impl Action {
pub fn new<S>(action: ActionType, label: S, url: Url) -> Self
where
S: Into<String>,
{
Self {
action,
label: label.into(),
url,
clear: None,
body: None,
}
}
#[inline]
pub fn clear(mut self, clear: bool) -> Self {
self.clear = Some(clear);
self
}
#[inline]
pub fn body(mut self, body: Value) -> Self {
self.body = Some(body);
self
}
}