sara_core/edit/
options.rs

1//! Edit options for modifying items.
2
3use crate::model::TraceabilityLinks;
4
5/// Options for editing an item.
6#[derive(Debug, Clone, Default)]
7pub struct EditOptions {
8    /// The item ID to edit.
9    pub item_id: String,
10    /// New name (if provided).
11    pub name: Option<String>,
12    /// New description (if provided).
13    pub description: Option<String>,
14    /// New refines references (if provided).
15    pub refines: Option<Vec<String>>,
16    /// New derives_from references (if provided).
17    pub derives_from: Option<Vec<String>>,
18    /// New satisfies references (if provided).
19    pub satisfies: Option<Vec<String>>,
20    /// New specification (if provided).
21    pub specification: Option<String>,
22    /// New platform (if provided).
23    pub platform: Option<String>,
24}
25
26impl EditOptions {
27    /// Creates new edit options for the given item ID.
28    pub fn new(item_id: impl Into<String>) -> Self {
29        Self {
30            item_id: item_id.into(),
31            ..Default::default()
32        }
33    }
34
35    /// Sets the name.
36    pub fn with_name(mut self, name: impl Into<String>) -> Self {
37        self.name = Some(name.into());
38        self
39    }
40
41    /// Sets the description.
42    pub fn with_description(mut self, description: impl Into<String>) -> Self {
43        self.description = Some(description.into());
44        self
45    }
46
47    /// Sets the refines references.
48    pub fn with_refines(mut self, refines: Vec<String>) -> Self {
49        self.refines = Some(refines);
50        self
51    }
52
53    /// Sets the derives_from references.
54    pub fn with_derives_from(mut self, derives_from: Vec<String>) -> Self {
55        self.derives_from = Some(derives_from);
56        self
57    }
58
59    /// Sets the satisfies references.
60    pub fn with_satisfies(mut self, satisfies: Vec<String>) -> Self {
61        self.satisfies = Some(satisfies);
62        self
63    }
64
65    /// Sets the specification.
66    pub fn with_specification(mut self, specification: impl Into<String>) -> Self {
67        self.specification = Some(specification.into());
68        self
69    }
70
71    /// Sets the platform.
72    pub fn with_platform(mut self, platform: impl Into<String>) -> Self {
73        self.platform = Some(platform.into());
74        self
75    }
76
77    /// Returns true if any modification was requested.
78    pub fn has_updates(&self) -> bool {
79        self.name.is_some()
80            || self.description.is_some()
81            || self.refines.is_some()
82            || self.derives_from.is_some()
83            || self.satisfies.is_some()
84            || self.specification.is_some()
85            || self.platform.is_some()
86    }
87}
88
89/// Values to apply during editing.
90#[derive(Debug, Clone)]
91pub struct EditedValues {
92    /// The name.
93    pub name: String,
94    /// Optional description.
95    pub description: Option<String>,
96    /// Optional specification.
97    pub specification: Option<String>,
98    /// Optional platform.
99    pub platform: Option<String>,
100    /// Traceability links.
101    pub traceability: TraceabilityLinks,
102}
103
104impl EditedValues {
105    /// Creates new edited values.
106    pub fn new(name: impl Into<String>) -> Self {
107        Self {
108            name: name.into(),
109            description: None,
110            specification: None,
111            platform: None,
112            traceability: TraceabilityLinks::default(),
113        }
114    }
115
116    /// Sets the description.
117    pub fn with_description(mut self, description: Option<String>) -> Self {
118        self.description = description;
119        self
120    }
121
122    /// Sets the specification.
123    pub fn with_specification(mut self, specification: Option<String>) -> Self {
124        self.specification = specification;
125        self
126    }
127
128    /// Sets the platform.
129    pub fn with_platform(mut self, platform: Option<String>) -> Self {
130        self.platform = platform;
131        self
132    }
133
134    /// Sets the traceability links.
135    pub fn with_traceability(mut self, traceability: TraceabilityLinks) -> Self {
136        self.traceability = traceability;
137        self
138    }
139}