Skip to main content

routa_core/models/
workspace.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6#[serde(rename_all = "lowercase")]
7pub enum WorkspaceStatus {
8    Active,
9    Archived,
10}
11
12impl WorkspaceStatus {
13    pub fn as_str(&self) -> &'static str {
14        match self {
15            Self::Active => "active",
16            Self::Archived => "archived",
17        }
18    }
19
20    #[allow(clippy::should_implement_trait)]
21    pub fn from_str(s: &str) -> Self {
22        match s {
23            "archived" => Self::Archived,
24            _ => Self::Active,
25        }
26    }
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(rename_all = "camelCase")]
31pub struct Workspace {
32    pub id: String,
33    pub title: String,
34    pub status: WorkspaceStatus,
35    #[serde(default)]
36    pub metadata: HashMap<String, String>,
37    pub created_at: DateTime<Utc>,
38    pub updated_at: DateTime<Utc>,
39}
40
41impl Workspace {
42    pub fn new(id: String, title: String, metadata: Option<HashMap<String, String>>) -> Self {
43        let now = Utc::now();
44        Self {
45            id,
46            title,
47            status: WorkspaceStatus::Active,
48            metadata: metadata.unwrap_or_default(),
49            created_at: now,
50            updated_at: now,
51        }
52    }
53}