dpp/document/v0/
accessors.rs

1use crate::document::{DocumentV0, DocumentV0Getters, DocumentV0Setters};
2use crate::identity::TimestampMillis;
3use crate::prelude::Revision;
4use platform_value::{Identifier, Value};
5use std::collections::BTreeMap;
6
7impl DocumentV0Getters for DocumentV0 {
8    /// Returns the document's unique identifier.
9    ///
10    /// # Returns
11    /// An `Identifier` representing the unique ID of the document.
12    fn id(&self) -> Identifier {
13        self.id
14    }
15
16    /// Returns the identifier of the document's owner.
17    ///
18    /// # Returns
19    /// An `Identifier` representing the owner's ID.
20    fn owner_id(&self) -> Identifier {
21        self.owner_id
22    }
23
24    /// Provides a reference to the document's properties.
25    ///
26    /// # Returns
27    /// A reference to a `BTreeMap<String, Value>` containing the document's properties.
28    fn properties(&self) -> &BTreeMap<String, Value> {
29        &self.properties
30    }
31
32    /// Provides a mutable reference to the document's properties.
33    ///
34    /// # Returns
35    /// A mutable reference to a `BTreeMap<String, Value>` containing the document's properties.
36    fn properties_mut(&mut self) -> &mut BTreeMap<String, Value> {
37        &mut self.properties
38    }
39
40    /// Returns the document's revision, if it is part
41    /// of the document. The document will have this field if it's schema has this document type
42    /// as mutable.
43    ///
44    /// # Returns
45    /// An `Option<Revision>` which is `Some(Revision)` if the document has a revision, or `None` if not.
46    fn revision(&self) -> Option<Revision> {
47        self.revision
48    }
49
50    /// Returns the timestamp of when the document was created, if it is part
51    /// of the document. The document will have this field if it's schema has it set as required.
52    ///
53    /// # Returns
54    /// An `Option<TimestampMillis>` representing the creation time in milliseconds, or `None` if not available.
55    fn created_at(&self) -> Option<TimestampMillis> {
56        self.created_at
57    }
58
59    /// Returns the timestamp of the last update to the document, if it is part
60    /// of the document. The document will have this field if it's schema has it set as required.
61    ///
62    /// # Returns
63    /// An `Option<TimestampMillis>` representing the update time in milliseconds, or `None` if not available.
64    fn updated_at(&self) -> Option<TimestampMillis> {
65        self.updated_at
66    }
67
68    /// Returns the timestamp of the last time the document was transferred, if it is part
69    /// of the document. The document will have this field if it's schema has it set as required.
70    ///
71    /// # Returns
72    /// An `Option<TimestampMillis>` representing the transferred at time in milliseconds, or `None` if not available.
73    fn transferred_at(&self) -> Option<TimestampMillis> {
74        self.transferred_at
75    }
76
77    /// Provides a reference to the document's unique identifier.
78    ///
79    /// # Returns
80    /// A reference to an `Identifier` representing the unique ID of the document.
81    fn id_ref(&self) -> &Identifier {
82        &self.id
83    }
84
85    /// Provides a reference to the document's owner identifier.
86    ///
87    /// # Returns
88    /// A reference to an `Identifier` representing the owner's ID.
89    fn owner_id_ref(&self) -> &Identifier {
90        &self.owner_id
91    }
92
93    /// Consumes the document and returns its properties.
94    ///
95    /// # Returns
96    /// A `BTreeMap<String, Value>` containing the document's properties.
97    fn properties_consumed(self) -> BTreeMap<String, Value> {
98        self.properties
99    }
100
101    /// Returns the block height at which the document was created, if it is part
102    /// of the document. The document will have this field if it's schema has it set as required.
103    ///
104    /// # Returns
105    /// An `Option<u64>` representing the creation block height, or `None` if not available.
106    fn created_at_block_height(&self) -> Option<u64> {
107        self.created_at_block_height
108    }
109
110    /// Returns the block height at which the document was last updated, if it is part
111    /// of the document. The document will have this field if it's schema has it set as required.
112    ///
113    /// # Returns
114    /// An `Option<u64>` representing the update block height, or `None` if not available.
115    fn updated_at_block_height(&self) -> Option<u64> {
116        self.updated_at_block_height
117    }
118
119    /// Returns the block height of the last time the document was transferred, if it is part
120    /// of the document. The document will have this field if it's schema has it set as required.
121    ///
122    /// # Returns
123    /// An `Option<u64>` representing the transfer block height, or `None` if not available.
124    fn transferred_at_block_height(&self) -> Option<u64> {
125        self.transferred_at_block_height
126    }
127
128    /// Returns the core network block height at which the document was created, if it is part
129    /// of the document. The document will have this field if it's schema has it set as required.
130    ///
131    /// # Returns
132    /// An `Option<u32>` representing the creation core block height, or `None` if not available.
133    fn created_at_core_block_height(&self) -> Option<u32> {
134        self.created_at_core_block_height
135    }
136
137    /// Returns the core network block height at which the document was last updated, if it is part
138    /// of the document. The document will have this field if it's schema has it set as required.
139    ///
140    /// # Returns
141    /// An `Option<u32>` representing the update core block height, or `None` if not available.
142    fn updated_at_core_block_height(&self) -> Option<u32> {
143        self.updated_at_core_block_height
144    }
145
146    /// Returns the core network block height of the last time the document was transferred, if it is part
147    /// of the document. The document will have this field if it's schema has it set as required.
148    ///
149    /// # Returns
150    /// An `Option<u32>` representing the transfer core block height, or `None` if not available.
151    fn transferred_at_core_block_height(&self) -> Option<u32> {
152        self.transferred_at_core_block_height
153    }
154
155    /// Returns the creator identifier of the document, if it is part
156    /// of the document. The document will have this field if it's schema has it set as required.
157    ///
158    /// # Returns
159    /// An `Option<Identifier>` representing the creator's ID, or `None` if not available.
160    fn creator_id(&self) -> Option<Identifier> {
161        self.creator_id
162    }
163}
164
165impl DocumentV0Setters for DocumentV0 {
166    /// Sets the document's unique identifier.
167    ///
168    /// # Parameters
169    /// - `id`: An `Identifier` to set as the document's unique ID.
170    fn set_id(&mut self, id: Identifier) {
171        self.id = id;
172    }
173
174    /// Sets the identifier of the document's owner.
175    ///
176    /// # Parameters
177    /// - `owner_id`: An `Identifier` to set as the document's owner ID.
178    fn set_owner_id(&mut self, owner_id: Identifier) {
179        self.owner_id = owner_id;
180    }
181
182    /// Sets the document's properties.
183    ///
184    /// # Parameters
185    /// - `properties`: A `BTreeMap<String, Value>` containing the properties to set for the document.
186    fn set_properties(&mut self, properties: BTreeMap<String, Value>) {
187        self.properties = properties;
188    }
189
190    /// Sets the document's revision. This is applicable if the document's schema indicates
191    /// the document type as mutable.
192    ///
193    /// # Parameters
194    /// - `revision`: An `Option<Revision>` to set as the document's revision. `None` indicates
195    ///   the document does not have a revision.
196    fn set_revision(&mut self, revision: Option<Revision>) {
197        self.revision = revision;
198    }
199
200    /// Bumps the document's revision if it has one. This is applicable if the document's schema indicates
201    /// the document type as mutable.
202    ///
203    fn bump_revision(&mut self) {
204        if let Some(revision) = self.revision {
205            self.revision = Some(revision.saturating_add(1))
206        }
207    }
208
209    /// Sets the timestamp of when the document was created. This is applicable if the document's
210    /// schema requires a creation timestamp.
211    ///
212    /// # Parameters
213    /// - `created_at`: An `Option<TimestampMillis>` to set as the document's creation timestamp.
214    ///   `None` indicates the timestamp is not available.
215    fn set_created_at(&mut self, created_at: Option<TimestampMillis>) {
216        self.created_at = created_at;
217    }
218
219    /// Sets the timestamp of the last update to the document. This is applicable if the document's
220    /// schema requires an update timestamp.
221    ///
222    /// # Parameters
223    /// - `updated_at`: An `Option<TimestampMillis>` to set as the document's last update timestamp.
224    ///   `None` indicates the timestamp is not available.
225    fn set_updated_at(&mut self, updated_at: Option<TimestampMillis>) {
226        self.updated_at = updated_at;
227    }
228
229    fn set_transferred_at(&mut self, transferred_at: Option<TimestampMillis>) {
230        self.transferred_at = transferred_at;
231    }
232
233    /// Sets the block height at which the document was created. This is applicable if the document's
234    /// schema requires this information.
235    ///
236    /// # Parameters
237    /// - `created_at_block_height`: An `Option<u64>` to set as the document's creation block height.
238    ///   `None` indicates the block height is not available.
239    fn set_created_at_block_height(&mut self, created_at_block_height: Option<u64>) {
240        self.created_at_block_height = created_at_block_height;
241    }
242
243    /// Sets the block height at which the document was last updated. This is applicable if the document's
244    /// schema requires this information.
245    ///
246    /// # Parameters
247    /// - `updated_at_block_height`: An `Option<u64>` to set as the document's last update block height.
248    ///   `None` indicates the block height is not available.
249    fn set_updated_at_block_height(&mut self, updated_at_block_height: Option<u64>) {
250        self.updated_at_block_height = updated_at_block_height;
251    }
252
253    fn set_transferred_at_block_height(&mut self, transferred_at_block_height: Option<u64>) {
254        self.transferred_at_block_height = transferred_at_block_height;
255    }
256
257    /// Sets the core network block height at which the document was created. This is applicable if the
258    /// document's schema requires this information.
259    ///
260    /// # Parameters
261    /// - `created_at_core_block_height`: An `Option<u32>` to set as the document's creation core block height.
262    ///   `None` indicates the core block height is not available.
263    fn set_created_at_core_block_height(&mut self, created_at_core_block_height: Option<u32>) {
264        self.created_at_core_block_height = created_at_core_block_height;
265    }
266
267    /// Sets the core network block height at which the document was last updated. This is applicable if the
268    /// document's schema requires this information.
269    ///
270    /// # Parameters
271    /// - `updated_at_core_block_height`: An `Option<u32>` to set as the document's last update core block height.
272    ///   `None` indicates the core block height is not available.
273    fn set_updated_at_core_block_height(&mut self, updated_at_core_block_height: Option<u32>) {
274        self.updated_at_core_block_height = updated_at_core_block_height;
275    }
276
277    fn set_transferred_at_core_block_height(
278        &mut self,
279        transferred_at_core_block_height: Option<u32>,
280    ) {
281        self.transferred_at_core_block_height = transferred_at_core_block_height;
282    }
283
284    /// Sets the creator identifier of the document. This is applicable if the document's
285    /// schema requires this information.
286    ///
287    /// # Parameters
288    /// - `creator_id`: An `Option<Identifier>` to set as the document's creator ID.
289    ///   `None` indicates the creator ID is not available.
290    fn set_creator_id(&mut self, creator_id: Option<Identifier>) {
291        self.creator_id = creator_id;
292    }
293}