use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum PluginAction {
Enable,
Disable,
SetParameter {
key: String,
value: serde_json::Value,
},
TriggerHook {
hook_name: String,
data: serde_json::Value,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginControl {
pub plugin_name: String,
pub action: PluginAction,
}
impl PluginControl {
pub fn enable(plugin_name: impl Into<String>) -> Self {
Self {
plugin_name: plugin_name.into(),
action: PluginAction::Enable,
}
}
pub fn disable(plugin_name: impl Into<String>) -> Self {
Self {
plugin_name: plugin_name.into(),
action: PluginAction::Disable,
}
}
pub fn set_param(
plugin_name: impl Into<String>,
key: impl Into<String>,
value: impl Into<serde_json::Value>,
) -> Self {
Self {
plugin_name: plugin_name.into(),
action: PluginAction::SetParameter {
key: key.into(),
value: value.into(),
},
}
}
pub fn trigger_hook(
plugin_name: impl Into<String>,
hook_name: impl Into<String>,
data: serde_json::Value,
) -> Self {
Self {
plugin_name: plugin_name.into(),
action: PluginAction::TriggerHook {
hook_name: hook_name.into(),
data,
},
}
}
}