use pe_core::PeError;
use crate::dependency::TaskDependency;
use crate::task::{Task, TaskId, TaskPriority, TaskStatus, TaskType};
#[async_trait::async_trait]
pub trait TaskRegistry: Send + Sync {
async fn create(&self, task: Task) -> Result<Task, PeError>;
async fn get(&self, id: &TaskId) -> Result<Option<Task>, PeError>;
async fn update(&self, task: &Task) -> Result<Task, PeError>;
async fn delete(&self, id: &TaskId) -> Result<bool, PeError>;
async fn restore(&self, id: &TaskId) -> Result<bool, PeError>;
async fn update_status(
&self,
id: &TaskId,
status: TaskStatus,
result: Option<serde_json::Value>,
error: Option<String>,
) -> Result<Task, PeError>;
async fn list(&self, filter: &TaskFilter) -> Result<Vec<Task>, PeError>;
async fn get_subtasks(&self, parent_id: &TaskId) -> Result<Vec<Task>, PeError>;
async fn get_tree(&self, root_id: &TaskId) -> Result<Vec<Task>, PeError>;
async fn add_dependency(&self, dep: TaskDependency) -> Result<(), PeError>;
async fn remove_dependency(
&self,
task_id: &TaskId,
depends_on_id: &TaskId,
) -> Result<(), PeError>;
async fn get_dependencies(&self, task_id: &TaskId) -> Result<Vec<TaskDependency>, PeError>;
async fn get_dependents(&self, task_id: &TaskId) -> Result<Vec<TaskDependency>, PeError>;
async fn get_ready_tasks(&self) -> Result<Vec<Task>, PeError>;
}
#[derive(Clone, Debug, Default)]
pub struct TaskFilter {
pub status: Option<TaskStatus>,
pub task_type: Option<TaskType>,
pub priority: Option<TaskPriority>,
pub agent_id: Option<String>,
pub assignee: Option<String>,
pub parent_id: Option<TaskId>,
pub tag: Option<String>,
pub include_deleted: bool,
pub limit: usize,
}
impl TaskFilter {
#[must_use]
pub fn with_status(mut self, status: TaskStatus) -> Self {
self.status = Some(status);
self
}
#[must_use]
pub fn with_task_type(mut self, tt: TaskType) -> Self {
self.task_type = Some(tt);
self
}
#[must_use]
pub fn with_priority(mut self, priority: TaskPriority) -> Self {
self.priority = Some(priority);
self
}
#[must_use]
pub fn with_agent(mut self, agent_id: impl Into<String>) -> Self {
self.agent_id = Some(agent_id.into());
self
}
#[must_use]
pub fn with_assignee(mut self, assignee: impl Into<String>) -> Self {
self.assignee = Some(assignee.into());
self
}
#[must_use]
pub fn with_parent(mut self, parent_id: impl Into<TaskId>) -> Self {
self.parent_id = Some(parent_id.into());
self
}
#[must_use]
pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
self.tag = Some(tag.into());
self
}
#[must_use]
pub fn with_limit(mut self, limit: usize) -> Self {
self.limit = limit;
self
}
#[must_use]
pub fn including_deleted(mut self) -> Self {
self.include_deleted = true;
self
}
}