gevulot_rs/models/metadata.rs
1use crate::proto::gevulot::gevulot;
2use serde::{Deserialize, Serialize};
3
4/// Metadata represents common metadata fields used across different resource types.
5///
6/// # Examples
7///
8/// ```
9/// use crate::models::Metadata;
10/// use crate::models::Label;
11///
12/// let metadata = Metadata {
13/// id: Some("task-123".to_string()),
14/// name: "my-task".to_string(),
15/// creator: Some("alice".to_string()),
16/// description: "An example task".to_string(),
17/// tags: vec!["tag1".to_string(), "tag2".to_string()],
18/// labels: vec![
19/// Label {
20/// key: "env".to_string(),
21/// value: "prod".to_string()
22/// }
23/// ],
24/// workflow_ref: None
25/// };
26/// ```
27#[derive(Serialize, Deserialize, Debug, Default)]
28pub struct Metadata {
29 /// Unique identifier for the resource
30 pub id: Option<String>,
31 /// Name of the resource
32 pub name: String,
33 /// Creator/owner of the resource
34 pub creator: Option<String>,
35 /// Detailed description of the resource
36 pub description: String,
37 /// List of searchable tags
38 pub tags: Vec<String>,
39 /// List of key-value labels
40 pub labels: Vec<Label>,
41 /// Reference to a parent workflow (only used in TaskMetadata)
42 #[serde(rename = "workflowRef")]
43 pub workflow_ref: Option<String>,
44}
45
46/// Label represents a key-value pair used for resource classification and filtering.
47///
48/// # Examples
49///
50/// ```
51/// use crate::models::Label;
52///
53/// let label = Label {
54/// key: "environment".to_string(),
55/// value: "production".to_string()
56/// };
57/// ```
58#[derive(Serialize, Deserialize, Debug)]
59pub struct Label {
60 /// The label key
61 pub key: String,
62 /// The label value
63 pub value: String,
64}
65
66impl From<gevulot::Label> for Label {
67 /// Converts a protobuf Label into our domain Label
68 fn from(proto: gevulot::Label) -> Self {
69 Label {
70 key: proto.key,
71 value: proto.value,
72 }
73 }
74}
75
76impl From<Label> for gevulot::Label {
77 /// Converts our domain Label into a protobuf Label
78 fn from(val: Label) -> Self {
79 gevulot::Label {
80 key: val.key,
81 value: val.value,
82 }
83 }
84}