1use crate::task::{SharedStateExt, Task};
2use serde::{Deserialize, Serialize};
3use std::time::Duration;
4use thiserror::Error;
5
6pub type TaskId = u128;
7
8#[derive(Debug, Error)]
9pub enum Error {
10 #[error("no task to complete, time until next repetition: {}s", time_until_next_repetition.as_secs())]
11 NoTaskToComplete {
12 time_until_next_repetition: Duration,
13 },
14 #[error("tasks facade is empty")]
15 NoTask,
16 #[error(transparent)]
17 IO(#[from] std::io::Error),
18}
19
20pub trait TasksFacade<'a, T: Task<'a>>: Serialize + Deserialize<'a> {
21 fn new(name: String, desired_retention: f64) -> Self;
22 fn get_name(&self) -> &str;
23 fn get_desired_retention(&self) -> f64;
24 fn set_desired_retention(&mut self, desired_retention: f64);
25 fn tasks_total(&self) -> usize;
26 fn tasks_to_complete(&self) -> usize;
27
28 fn complete_task(
32 &mut self,
33 interaction: &mut impl FnMut(
34 TaskId,
35 s_text_input_f::Blocks,
36 ) -> std::io::Result<s_text_input_f::Response>,
37 ) -> Result<(), Error>;
38 fn insert(&mut self, task: T);
39 fn create_task(&mut self, input: s_text_input_f::BlocksWithAnswer);
40
41 fn iter<'t>(&'t self) -> impl Iterator<Item = (&'t T, TaskId)>
43 where
44 T: 't;
45 fn remove(&mut self, id: TaskId) -> bool;
48
49 fn optimize(&mut self) -> Result<(), Box<dyn std::error::Error>>
53 where
54 T::SharedState: SharedStateExt<'a, T>;
55}