Skip to main content

stint_core/models/
project.rs

1//! Project domain model.
2
3use std::path::PathBuf;
4use time::OffsetDateTime;
5
6use super::types::ProjectId;
7
8/// Whether a project is actively tracked or archived.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum ProjectStatus {
11    /// Project is actively tracked.
12    Active,
13    /// Project is archived and hidden from default listings.
14    Archived,
15}
16
17impl ProjectStatus {
18    /// Returns the status as a lowercase string for storage.
19    pub fn as_str(&self) -> &'static str {
20        match self {
21            Self::Active => "active",
22            Self::Archived => "archived",
23        }
24    }
25
26    /// Parses a status from a stored string value.
27    pub fn from_str_value(s: &str) -> Option<Self> {
28        match s {
29            "active" => Some(Self::Active),
30            "archived" => Some(Self::Archived),
31            _ => None,
32        }
33    }
34}
35
36/// How a project was created.
37#[derive(Debug, Clone, PartialEq, Eq)]
38pub enum ProjectSource {
39    /// Manually registered via `stint project add`.
40    Manual,
41    /// Auto-discovered from a `.git` directory.
42    Discovered,
43}
44
45impl ProjectSource {
46    /// Returns the source as a lowercase string for storage.
47    pub fn as_str(&self) -> &'static str {
48        match self {
49            Self::Manual => "manual",
50            Self::Discovered => "discovered",
51        }
52    }
53
54    /// Parses a source from a stored string value.
55    pub fn from_str_value(s: &str) -> Self {
56        match s {
57            "discovered" => Self::Discovered,
58            _ => Self::Manual,
59        }
60    }
61}
62
63/// A tracked project.
64#[derive(Debug, Clone, PartialEq)]
65pub struct Project {
66    /// Unique identifier.
67    pub id: ProjectId,
68    /// User-facing name (unique).
69    pub name: String,
70    /// Directories that map to this project.
71    pub paths: Vec<PathBuf>,
72    /// User-defined tags.
73    pub tags: Vec<String>,
74    /// Hourly rate in cents (e.g., 15000 = $150.00).
75    pub hourly_rate_cents: Option<i64>,
76    /// Whether this project is active or archived.
77    pub status: ProjectStatus,
78    /// How this project was created.
79    pub source: ProjectSource,
80    /// When this project was created.
81    pub created_at: OffsetDateTime,
82    /// When this project was last updated.
83    pub updated_at: OffsetDateTime,
84}