use super::AttributeMap;
use super::clone::option_string_to_owned;
use std::borrow::Cow;
use std::num::NonZeroU32;
use strum_macros::IntoStaticStr;
#[derive(Serialize, Deserialize, IntoStaticStr, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case", tag = "module", content = "data")]
pub enum Module<'t> {
Backlinks { page: Option<Cow<'t, str>> },
#[serde(rename_all = "kebab-case")]
Categories { include_hidden: bool },
#[serde(rename_all = "kebab-case")]
Join {
button_text: Option<Cow<'t, str>>,
attributes: AttributeMap<'t>,
},
#[serde(rename_all = "kebab-case")]
PageTree {
root: Option<Cow<'t, str>>,
show_root: bool,
depth: Option<NonZeroU32>,
},
Rate,
}
impl Module<'_> {
#[inline]
pub fn name(&self) -> &'static str {
self.into()
}
pub fn to_owned(&self) -> Module<'static> {
match self {
Module::Backlinks { page } => Module::Backlinks {
page: option_string_to_owned(page),
},
Module::Categories { include_hidden } => Module::Categories {
include_hidden: *include_hidden,
},
Module::Join {
button_text,
attributes,
} => Module::Join {
button_text: option_string_to_owned(button_text),
attributes: attributes.to_owned(),
},
Module::PageTree {
root,
show_root,
depth,
} => Module::PageTree {
root: option_string_to_owned(root),
show_root: *show_root,
depth: *depth,
},
Module::Rate => Module::Rate,
}
}
}