use std::collections::BTreeMap;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ReadingRow {
pub id: String,
pub title: String,
pub subtitle: Option<String>,
pub group: Option<String>,
pub icon: Option<String>,
pub facts: Vec<String>,
pub fields: Vec<String>,
pub action: Option<String>,
pub arguments: BTreeMap<String, serde_json::Value>,
pub app: Option<String>,
}
impl ReadingRow {
#[must_use]
pub fn new(id: impl Into<String>, title: impl Into<String>) -> Self {
Self {
id: id.into(),
title: title.into(),
..Self::default()
}
}
#[must_use]
pub fn subtitled(mut self, subtitle: impl Into<String>) -> Self {
let subtitle = subtitle.into();
self.subtitle = (!subtitle.trim().is_empty()).then(|| subtitle.trim().to_owned());
self
}
#[must_use]
pub fn grouped(mut self, group: impl Into<String>) -> Self {
self.group = Some(group.into());
self
}
#[must_use]
pub fn icon(mut self, icon: impl Into<String>) -> Self {
self.icon = Some(icon.into());
self
}
#[must_use]
pub fn fact(mut self, fact: impl Into<String>) -> Self {
let fact = fact.into();
if !fact.trim().is_empty() {
self.facts.push(fact);
}
self
}
#[must_use]
pub fn field(mut self, field: impl Into<String>) -> Self {
let field = field.into();
if !field.trim().is_empty() {
self.fields.push(field);
}
self
}
#[must_use]
pub fn opened_by<K, V>(
mut self,
action: impl Into<String>,
arguments: impl IntoIterator<Item = (K, V)>,
) -> Self
where
K: Into<String>,
V: Into<serde_json::Value>,
{
self.action = Some(action.into());
self.arguments.extend(
arguments
.into_iter()
.map(|(name, value)| (name.into(), value.into())),
);
self
}
#[must_use]
pub fn shown_by(mut self, app: impl Into<String>) -> Self {
self.app = Some(app.into());
self
}
}