Skip to main content

ito_domain/tasks/
repository.rs

1//! Task repository port definitions.
2
3use super::parse::{ProgressInfo, TaskItem, TasksParseResult};
4use crate::errors::DomainResult;
5
6/// Port for accessing task data.
7///
8/// This trait defines the interface for reading task tracking information.
9/// Implementations (in the core layer) handle the file I/O and parsing details.
10///
11/// Consumers in the domain or adapter layers should rely on this trait to remain
12/// decoupled from storage specifics.
13pub trait TaskRepository {
14    /// Load all tasks for a change.
15    ///
16    /// Returns the full parse result including diagnostics.
17    fn load_tasks(&self, change_id: &str) -> DomainResult<TasksParseResult>;
18
19    /// Get task progress for a change.
20    ///
21    /// This is a convenience method that returns just the progress info.
22    fn get_progress(&self, change_id: &str) -> DomainResult<ProgressInfo> {
23        let result = self.load_tasks(change_id)?;
24        Ok(result.progress)
25    }
26
27    /// Get task counts (completed, total) for a change.
28    ///
29    /// Implementations should return `(0, 0)` when the tasks file doesn't exist.
30    fn get_task_counts(&self, change_id: &str) -> DomainResult<(u32, u32)> {
31        let progress = self.get_progress(change_id)?;
32        Ok((progress.complete as u32, progress.total as u32))
33    }
34
35    /// Check if a change has any tasks defined.
36    fn has_tasks(&self, change_id: &str) -> DomainResult<bool> {
37        let progress = self.get_progress(change_id)?;
38        Ok(progress.total > 0)
39    }
40
41    /// Get all tasks for a change.
42    fn get_tasks(&self, change_id: &str) -> DomainResult<Vec<TaskItem>> {
43        let result = self.load_tasks(change_id)?;
44        Ok(result.tasks)
45    }
46}