use hyperlog_core::log::ItemState; use crate::{ services::{ create_item::{self, CreateItem, CreateItemExt}, create_root::{self, CreateRoot, CreateRootExt}, create_section::{self, CreateSection, CreateSectionExt}, }, state::SharedState, }; #[allow(dead_code)] pub enum Command { CreateRoot { root: String, }, CreateSection { root: String, path: Vec, }, CreateItem { root: String, path: Vec, title: String, description: String, state: ItemState, }, UpdateItem { root: String, path: Vec, title: String, description: String, state: ItemState, }, ToggleItem { root: String, path: Vec, }, Move { root: String, src: Vec, dest: Vec, }, } #[allow(dead_code)] pub struct Commander { create_root: CreateRoot, create_section: CreateSection, create_item: CreateItem, } impl Commander { pub fn new( create_root: CreateRoot, create_section: CreateSection, create_item: CreateItem, ) -> Self { Self { create_root, create_section, create_item, } } pub async fn execute(&self, cmd: Command) -> anyhow::Result<()> { match cmd { Command::CreateRoot { root } => { self.create_root .execute(create_root::Request { root }) .await?; Ok(()) } Command::CreateSection { root, path } => { self.create_section .execute(create_section::Request { root, path }) .await?; Ok(()) } Command::CreateItem { root, path, title, description, state, } => { self.create_item .execute(create_item::Request { root, path, title, description, state, }) .await?; Ok(()) } Command::UpdateItem { root, path, title, description, state, } => todo!(), Command::ToggleItem { root, path } => todo!(), Command::Move { root, src, dest } => todo!(), } } } pub trait CommanderExt { fn commander(&self) -> Commander; } impl CommanderExt for SharedState { fn commander(&self) -> Commander { Commander::new( self.create_root_service(), self.create_section_service(), self.create_item_service(), ) } }