intent_engine/db/
models.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use sqlx::FromRow;
4
5#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
6pub struct Task {
7    pub id: i64,
8    pub parent_id: Option<i64>,
9    pub name: String,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub spec: Option<String>,
12    pub status: String,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub complexity: Option<i32>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub priority: Option<i32>,
17    pub first_todo_at: Option<DateTime<Utc>>,
18    pub first_doing_at: Option<DateTime<Utc>>,
19    pub first_done_at: Option<DateTime<Utc>>,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct TaskWithEvents {
24    #[serde(flatten)]
25    pub task: Task,
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub events_summary: Option<EventsSummary>,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct EventsSummary {
32    pub total_count: i64,
33    pub recent_events: Vec<Event>,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
37pub struct Event {
38    pub id: i64,
39    pub task_id: i64,
40    pub timestamp: DateTime<Utc>,
41    pub log_type: String,
42    pub discussion_data: String,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
46pub struct WorkspaceState {
47    pub key: String,
48    pub value: String,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct Report {
53    pub summary: ReportSummary,
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub tasks: Option<Vec<Task>>,
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub events: Option<Vec<Event>>,
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct ReportSummary {
62    pub total_tasks: i64,
63    pub tasks_by_status: StatusBreakdown,
64    pub total_events: i64,
65    pub date_range: Option<DateRange>,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct StatusBreakdown {
70    pub todo: i64,
71    pub doing: i64,
72    pub done: i64,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct DateRange {
77    pub from: DateTime<Utc>,
78    pub to: DateTime<Utc>,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct DoneTaskResponse {
83    pub completed_task: Task,
84    pub workspace_status: WorkspaceStatus,
85    pub next_step_suggestion: NextStepSuggestion,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct WorkspaceStatus {
90    pub current_task_id: Option<i64>,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(tag = "type")]
95pub enum NextStepSuggestion {
96    #[serde(rename = "PARENT_IS_READY")]
97    ParentIsReady {
98        message: String,
99        parent_task_id: i64,
100        parent_task_name: String,
101    },
102    #[serde(rename = "SIBLING_TASKS_REMAIN")]
103    SiblingTasksRemain {
104        message: String,
105        parent_task_id: i64,
106        parent_task_name: String,
107        remaining_siblings_count: i64,
108    },
109    #[serde(rename = "TOP_LEVEL_TASK_COMPLETED")]
110    TopLevelTaskCompleted {
111        message: String,
112        completed_task_id: i64,
113        completed_task_name: String,
114    },
115    #[serde(rename = "NO_PARENT_CONTEXT")]
116    NoParentContext {
117        message: String,
118        completed_task_id: i64,
119        completed_task_name: String,
120    },
121    #[serde(rename = "WORKSPACE_IS_CLEAR")]
122    WorkspaceIsClear {
123        message: String,
124        completed_task_id: i64,
125    },
126}
127
128#[derive(Debug, Clone, Serialize, Deserialize)]
129pub struct TaskSearchResult {
130    #[serde(flatten)]
131    pub task: Task,
132    pub match_snippet: String,
133}