use crate::id::ActionId;
use crate::input::ActionInput;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ActionSpec {
id: ActionId,
title: String,
description: Option<String>,
category: Option<String>,
keywords: Vec<String>,
inputs: Vec<ActionInput>,
availability: Availability,
}
impl ActionSpec {
pub fn new(id: impl Into<ActionId>, title: impl Into<String>) -> Self {
Self {
id: id.into(),
title: title.into(),
description: None,
category: None,
keywords: Vec::new(),
inputs: Vec::new(),
availability: Availability::Enabled,
}
}
pub fn id(&self) -> &ActionId {
&self.id
}
pub fn title(&self) -> &str {
&self.title
}
pub fn description(&self) -> Option<&str> {
self.description.as_deref()
}
pub fn category(&self) -> Option<&str> {
self.category.as_deref()
}
pub fn keywords(&self) -> impl Iterator<Item = &str> {
self.keywords.iter().map(String::as_str)
}
pub fn inputs(&self) -> &[ActionInput] {
&self.inputs
}
pub fn availability(&self) -> &Availability {
&self.availability
}
pub fn with_description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
pub fn with_category(mut self, category: impl Into<String>) -> Self {
self.category = Some(category.into());
self
}
pub fn with_keywords(mut self, keywords: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.keywords = keywords.into_iter().map(Into::into).collect();
self
}
pub fn with_input(mut self, input: ActionInput) -> Self {
self.inputs.push(input);
self
}
pub fn with_availability(mut self, availability: Availability) -> Self {
self.availability = availability;
self
}
pub fn is_hidden(&self) -> bool {
matches!(self.availability, Availability::Hidden)
}
pub fn is_enabled(&self) -> bool {
matches!(self.availability, Availability::Enabled)
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Availability {
Enabled,
Disabled {
reason: String,
},
Hidden,
}