use std::io;
use std::path::PathBuf;
use thiserror::Error;
use super::parse::TaskItem;
pub type TaskMutationServiceResult<T> = Result<T, TaskMutationError>;
#[derive(Debug, Clone)]
pub struct TaskMutationResult {
pub change_id: String,
pub task: TaskItem,
pub revision: Option<String>,
}
#[derive(Debug, Clone)]
pub struct TaskInitResult {
pub change_id: String,
pub path: Option<PathBuf>,
pub existed: bool,
pub revision: Option<String>,
}
#[derive(Debug, Error)]
pub enum TaskMutationError {
#[error("I/O failure while {context}: {source}")]
Io {
context: String,
#[source]
source: io::Error,
},
#[error("{0}")]
Validation(String),
#[error("{0}")]
NotFound(String),
#[error("{0}")]
Other(String),
}
impl TaskMutationError {
pub fn io(context: impl Into<String>, source: io::Error) -> Self {
Self::Io {
context: context.into(),
source,
}
}
pub fn validation(message: impl Into<String>) -> Self {
Self::Validation(message.into())
}
pub fn not_found(message: impl Into<String>) -> Self {
Self::NotFound(message.into())
}
pub fn other(message: impl Into<String>) -> Self {
Self::Other(message.into())
}
}
pub trait TaskMutationService: Send + Sync {
fn load_tasks_markdown(&self, change_id: &str) -> TaskMutationServiceResult<Option<String>>;
fn init_tasks(&self, change_id: &str) -> TaskMutationServiceResult<TaskInitResult>;
fn start_task(
&self,
change_id: &str,
task_id: &str,
) -> TaskMutationServiceResult<TaskMutationResult>;
fn complete_task(
&self,
change_id: &str,
task_id: &str,
note: Option<String>,
) -> TaskMutationServiceResult<TaskMutationResult>;
fn shelve_task(
&self,
change_id: &str,
task_id: &str,
reason: Option<String>,
) -> TaskMutationServiceResult<TaskMutationResult>;
fn unshelve_task(
&self,
change_id: &str,
task_id: &str,
) -> TaskMutationServiceResult<TaskMutationResult>;
fn add_task(
&self,
change_id: &str,
title: &str,
wave: Option<u32>,
) -> TaskMutationServiceResult<TaskMutationResult>;
}