use serde::{Deserialize, Serialize};
use std::str::FromStr;
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[cfg_attr(feature = "schema-export", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum TrackerItemStatus {
#[default]
Pending,
InProgress,
Completed,
Blocked,
#[serde(other)]
Unknown,
}
impl TrackerItemStatus {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Pending => "pending",
Self::InProgress => "in_progress",
Self::Completed => "completed",
Self::Blocked => "blocked",
Self::Unknown => "unknown",
}
}
}
impl FromStr for TrackerItemStatus {
type Err = ();
fn from_str(raw: &str) -> Result<Self, Self::Err> {
match raw {
"pending" => Ok(Self::Pending),
"in_progress" => Ok(Self::InProgress),
"completed" => Ok(Self::Completed),
"blocked" => Ok(Self::Blocked),
_ => Err(()),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schema-export", derive(schemars::JsonSchema))]
pub struct TrackerItemState {
pub index_path: String,
pub description: String,
pub status: TrackerItemStatus,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schema-export", derive(schemars::JsonSchema))]
pub struct TrackerSnapshot {
pub title: String,
pub completed: usize,
pub total: usize,
pub items: Vec<TrackerItemState>,
}