use uuid::Uuid;
use crate::ser::tags::Tag;
use crate::ser::tags::Templates;
pub type Id = Uuid;
#[derive(Clone, Debug, PartialEq)]
pub struct Task {
pub id: Id,
pub summary: String,
pub details: String,
pub tags: Vec<Tag>,
pub position: Option<f64>,
}
#[cfg(any(test, feature = "test"))]
impl Task {
pub fn new<S>(summary: S) -> Self
where
S: Into<String>,
{
Self {
id: Id::new_v4(),
summary: summary.into(),
details: Default::default(),
tags: Default::default(),
position: None,
}
}
pub fn with_details<D>(mut self, details: D) -> Self
where
D: ToString,
{
self.details = details.to_string();
self
}
pub fn with_tags<I>(mut self, tags: I) -> Self
where
I: IntoIterator<Item = Tag>,
{
self.tags = tags.into_iter().collect();
self
}
}
#[derive(Debug, Default, PartialEq, Eq)]
pub struct TasksMeta {
pub templates: Templates,
}
#[derive(Debug, Default, PartialEq)]
pub struct Tasks(pub Vec<Task>);
#[cfg(test)]
impl Tasks {
pub fn into_task_vec(mut self) -> Vec<Task> {
self.0.iter_mut().for_each(|task| {
let _prev = task.position.take();
});
self.0
}
}
#[cfg(any(test, feature = "test"))]
impl From<Vec<Task>> for Tasks {
fn from(tasks: Vec<Task>) -> Self {
Self(tasks)
}
}