use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use uuid::Uuid;
use super::{assingee, comment, path, priority, recurring, state, tag, todo};
use crate::utils::{handler, Functions};
pub enum FIELDS {
TODO(Functions<todo::Todo, todo::FIELDS>),
STATE(Functions<state::State, state::FIELDS>),
TAG(Functions<tag::Tag, tag::FIELDS>),
RECURRING(Functions<recurring::Recurring, recurring::FIELDS>),
PATH(Functions<path::Path, path::FIELDS>),
ASSINGEE(Functions<assingee::Assingee, assingee::FIELDS>),
PRIORITY(Functions<priority::Priority, priority::FIELDS>),
COMMENT(Functions<comment::Comment, comment::FIELDS>),
}
#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Rodo {
todos: HashMap<Uuid, todo::Todo>,
states: HashMap<Uuid, state::State>,
tags: HashMap<Uuid, tag::Tag>,
recurring: HashMap<Uuid, recurring::Recurring>,
priorities: HashMap<Uuid, priority::Priority>,
paths: HashMap<Uuid, path::Path>,
assingees: HashMap<Uuid, assingee::Assingee>,
comments: HashMap<Uuid, comment::Comment>,
}
impl Rodo {
pub fn new() -> Self {
Self {
todos: HashMap::new(),
states: HashMap::new(),
tags: HashMap::new(),
recurring: HashMap::new(),
priorities: HashMap::new(),
paths: HashMap::new(),
assingees: HashMap::new(),
comments: HashMap::new(),
}
}
pub fn parse(&mut self, field: FIELDS) {
match field {
FIELDS::TODO(f) => handler(&mut self.todos, f),
FIELDS::STATE(f) => handler(&mut self.states, f),
FIELDS::TAG(f) => handler(&mut self.tags, f),
FIELDS::RECURRING(f) => handler(&mut self.recurring, f),
FIELDS::PRIORITY(f) => handler(&mut self.priorities, f),
FIELDS::PATH(f) => handler(&mut self.paths, f),
FIELDS::ASSINGEE(f) => handler(&mut self.assingees, f),
FIELDS::COMMENT(f) => handler(&mut self.comments, f),
}
}
}