Skip to main content

xtask_todo_lib/
model.rs

1//! Todo item and list options (filter, sort).
2
3use std::time::SystemTime;
4
5use crate::priority::Priority;
6use crate::repeat::RepeatRule;
7
8/// A single todo item.
9#[derive(Clone, Eq, PartialEq)]
10pub struct Todo {
11    pub id: crate::id::TodoId,
12    pub title: String,
13    pub completed: bool,
14    pub created_at: SystemTime,
15    /// When the todo was marked completed; None if still open.
16    pub completed_at: Option<SystemTime>,
17    /// Optional longer description.
18    pub description: Option<String>,
19    /// Optional due date (ISO 8601 date, e.g. YYYY-MM-DD).
20    pub due_date: Option<String>,
21    /// Optional priority.
22    pub priority: Option<Priority>,
23    /// Tags for grouping/filtering.
24    pub tags: Vec<String>,
25    /// Optional repeat rule for recurring tasks.
26    pub repeat_rule: Option<RepeatRule>,
27    /// Optional end date for recurrence (YYYY-MM-DD); no next instance if next due > this.
28    pub repeat_until: Option<String>,
29    /// Optional remaining occurrences for recurrence; no next instance when this is 0 or 1 (1 = last).
30    pub repeat_count: Option<u32>,
31}
32
33/// Partial update for a todo; only `Some` fields are applied.
34/// When `repeat_rule_clear` is true, `repeat_rule` is set to None (e.g. for CLI `--clear-repeat-rule`).
35#[derive(Clone, Default)]
36pub struct TodoPatch {
37    pub title: Option<String>,
38    pub description: Option<String>,
39    pub due_date: Option<String>,
40    pub priority: Option<Priority>,
41    pub tags: Option<Vec<String>>,
42    pub repeat_rule: Option<RepeatRule>,
43    pub repeat_until: Option<String>,
44    pub repeat_count: Option<u32>,
45    /// When true, clear `repeat_rule` (set to None).
46    pub repeat_rule_clear: bool,
47}
48
49/// Filter criteria for listing todos.
50#[derive(Clone, Default)]
51pub struct ListFilter {
52    /// If set, filter by completed status.
53    pub status: Option<bool>,
54    /// If set, only items with this priority.
55    pub priority: Option<Priority>,
56    /// If set, item must have at least one of these tags.
57    pub tags_any: Option<Vec<String>>,
58    /// If set, `due_date` must be <= this (YYYY-MM-DD).
59    pub due_before: Option<String>,
60    /// If set, `due_date` must be >= this (YYYY-MM-DD).
61    pub due_after: Option<String>,
62}
63
64/// Sort order for listing.
65#[derive(Clone, Copy, Default)]
66pub enum ListSort {
67    #[default]
68    CreatedAt,
69    DueDate,
70    Priority,
71    Title,
72}
73
74/// Options for list (filter + sort).
75#[derive(Clone, Default)]
76pub struct ListOptions {
77    pub filter: Option<ListFilter>,
78    pub sort: ListSort,
79}