Skip to main content

jacquard_api/network_slices/tools/bug/
issue.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: network.slices.tools.bug.issue
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::deps::smol_str::SmolStr;
18use jacquard_common::types::collection::{Collection, RecordError};
19use jacquard_common::types::string::{AtUri, Cid, Datetime};
20use jacquard_common::types::uri::{RecordUri, UriError};
21use jacquard_common::types::value::Data;
22use jacquard_common::xrpc::XrpcResp;
23use jacquard_derive::{IntoStatic, lexicon};
24use jacquard_lexicon::lexicon::LexiconDoc;
25use jacquard_lexicon::schema::LexiconSchema;
26
27#[allow(unused_imports)]
28use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
29use serde::{Serialize, Deserialize};
30
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(
33    rename_all = "camelCase",
34    rename = "network.slices.tools.bug.issue",
35    tag = "$type",
36    bound(deserialize = "S: Deserialize<'de> + BosStr")
37)]
38pub struct Issue<S: BosStr = DefaultStr> {
39    ///Reference to the bug report
40    pub bug: AtUri<S>,
41    pub created_at: Datetime,
42    ///Reference to the linked issue
43    pub issue: AtUri<S>,
44    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
45    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
46}
47
48/// Typed wrapper for GetRecord response with this collection's record type.
49
50#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
51#[serde(rename_all = "camelCase")]
52pub struct IssueGetRecordOutput<S: BosStr = DefaultStr> {
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub cid: Option<Cid<S>>,
55    pub uri: AtUri<S>,
56    pub value: Issue<S>,
57}
58
59impl<S: BosStr> Issue<S> {
60    pub fn uri(uri: S) -> Result<RecordUri<S, IssueRecord>, UriError> {
61        RecordUri::try_from_uri(AtUri::new(uri)?)
62    }
63}
64
65/// Marker type for deserializing records from this collection.
66
67#[derive(Debug, Serialize, Deserialize)]
68pub struct IssueRecord;
69impl XrpcResp for IssueRecord {
70    const NSID: &'static str = "network.slices.tools.bug.issue";
71    const ENCODING: &'static str = "application/json";
72    type Output<S: BosStr> = IssueGetRecordOutput<S>;
73    type Err = RecordError;
74}
75
76impl<S: BosStr> From<IssueGetRecordOutput<S>> for Issue<S> {
77    fn from(output: IssueGetRecordOutput<S>) -> Self {
78        output.value
79    }
80}
81
82impl<S: BosStr> Collection for Issue<S> {
83    const NSID: &'static str = "network.slices.tools.bug.issue";
84    type Record = IssueRecord;
85}
86
87impl Collection for IssueRecord {
88    const NSID: &'static str = "network.slices.tools.bug.issue";
89    type Record = IssueRecord;
90}
91
92impl<S: BosStr> LexiconSchema for Issue<S> {
93    fn nsid() -> &'static str {
94        "network.slices.tools.bug.issue"
95    }
96    fn def_name() -> &'static str {
97        "main"
98    }
99    fn lexicon_doc() -> LexiconDoc<'static> {
100        lexicon_doc_network_slices_tools_bug_issue()
101    }
102    fn validate(&self) -> Result<(), ConstraintError> {
103        Ok(())
104    }
105}
106
107pub mod issue_state {
108
109    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
110    #[allow(unused)]
111    use ::core::marker::PhantomData;
112    mod sealed {
113        pub trait Sealed {}
114    }
115    /// State trait tracking which required fields have been set
116    pub trait State: sealed::Sealed {
117        type Bug;
118        type CreatedAt;
119        type Issue;
120    }
121    /// Empty state - all required fields are unset
122    pub struct Empty(());
123    impl sealed::Sealed for Empty {}
124    impl State for Empty {
125        type Bug = Unset;
126        type CreatedAt = Unset;
127        type Issue = Unset;
128    }
129    ///State transition - sets the `bug` field to Set
130    pub struct SetBug<St: State = Empty>(PhantomData<fn() -> St>);
131    impl<St: State> sealed::Sealed for SetBug<St> {}
132    impl<St: State> State for SetBug<St> {
133        type Bug = Set<members::bug>;
134        type CreatedAt = St::CreatedAt;
135        type Issue = St::Issue;
136    }
137    ///State transition - sets the `created_at` field to Set
138    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
139    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
140    impl<St: State> State for SetCreatedAt<St> {
141        type Bug = St::Bug;
142        type CreatedAt = Set<members::created_at>;
143        type Issue = St::Issue;
144    }
145    ///State transition - sets the `issue` field to Set
146    pub struct SetIssue<St: State = Empty>(PhantomData<fn() -> St>);
147    impl<St: State> sealed::Sealed for SetIssue<St> {}
148    impl<St: State> State for SetIssue<St> {
149        type Bug = St::Bug;
150        type CreatedAt = St::CreatedAt;
151        type Issue = Set<members::issue>;
152    }
153    /// Marker types for field names
154    #[allow(non_camel_case_types)]
155    pub mod members {
156        ///Marker type for the `bug` field
157        pub struct bug(());
158        ///Marker type for the `created_at` field
159        pub struct created_at(());
160        ///Marker type for the `issue` field
161        pub struct issue(());
162    }
163}
164
165/// Builder for constructing an instance of this type.
166pub struct IssueBuilder<St: issue_state::State, S: BosStr = DefaultStr> {
167    _state: PhantomData<fn() -> St>,
168    _fields: (Option<AtUri<S>>, Option<Datetime>, Option<AtUri<S>>),
169    _type: PhantomData<fn() -> S>,
170}
171
172impl Issue<DefaultStr> {
173    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
174    pub fn new() -> IssueBuilder<issue_state::Empty, DefaultStr> {
175        IssueBuilder::new()
176    }
177}
178
179impl<S: BosStr> Issue<S> {
180    /// Create a new builder for this type
181    pub fn builder() -> IssueBuilder<issue_state::Empty, S> {
182        IssueBuilder::builder()
183    }
184}
185
186impl IssueBuilder<issue_state::Empty, DefaultStr> {
187    /// Create a new builder with all fields unset, using the default string type, if needed
188    pub fn new() -> Self {
189        IssueBuilder {
190            _state: PhantomData,
191            _fields: (None, None, None),
192            _type: PhantomData,
193        }
194    }
195}
196
197impl<S: BosStr> IssueBuilder<issue_state::Empty, S> {
198    /// Create a new builder with all fields unset
199    pub fn builder() -> Self {
200        IssueBuilder {
201            _state: PhantomData,
202            _fields: (None, None, None),
203            _type: PhantomData,
204        }
205    }
206}
207
208impl<St, S: BosStr> IssueBuilder<St, S>
209where
210    St: issue_state::State,
211    St::Bug: issue_state::IsUnset,
212{
213    /// Set the `bug` field (required)
214    pub fn bug(
215        mut self,
216        value: impl Into<AtUri<S>>,
217    ) -> IssueBuilder<issue_state::SetBug<St>, S> {
218        self._fields.0 = Option::Some(value.into());
219        IssueBuilder {
220            _state: PhantomData,
221            _fields: self._fields,
222            _type: PhantomData,
223        }
224    }
225}
226
227impl<St, S: BosStr> IssueBuilder<St, S>
228where
229    St: issue_state::State,
230    St::CreatedAt: issue_state::IsUnset,
231{
232    /// Set the `createdAt` field (required)
233    pub fn created_at(
234        mut self,
235        value: impl Into<Datetime>,
236    ) -> IssueBuilder<issue_state::SetCreatedAt<St>, S> {
237        self._fields.1 = Option::Some(value.into());
238        IssueBuilder {
239            _state: PhantomData,
240            _fields: self._fields,
241            _type: PhantomData,
242        }
243    }
244}
245
246impl<St, S: BosStr> IssueBuilder<St, S>
247where
248    St: issue_state::State,
249    St::Issue: issue_state::IsUnset,
250{
251    /// Set the `issue` field (required)
252    pub fn issue(
253        mut self,
254        value: impl Into<AtUri<S>>,
255    ) -> IssueBuilder<issue_state::SetIssue<St>, S> {
256        self._fields.2 = Option::Some(value.into());
257        IssueBuilder {
258            _state: PhantomData,
259            _fields: self._fields,
260            _type: PhantomData,
261        }
262    }
263}
264
265impl<St, S: BosStr> IssueBuilder<St, S>
266where
267    St: issue_state::State,
268    St::Bug: issue_state::IsSet,
269    St::CreatedAt: issue_state::IsSet,
270    St::Issue: issue_state::IsSet,
271{
272    /// Build the final struct.
273    pub fn build(self) -> Issue<S> {
274        Issue {
275            bug: self._fields.0.unwrap(),
276            created_at: self._fields.1.unwrap(),
277            issue: self._fields.2.unwrap(),
278            extra_data: Default::default(),
279        }
280    }
281    /// Build the final struct with custom extra_data.
282    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Issue<S> {
283        Issue {
284            bug: self._fields.0.unwrap(),
285            created_at: self._fields.1.unwrap(),
286            issue: self._fields.2.unwrap(),
287            extra_data: Some(extra_data),
288        }
289    }
290}
291
292fn lexicon_doc_network_slices_tools_bug_issue() -> LexiconDoc<'static> {
293    #[allow(unused_imports)]
294    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
295    use jacquard_lexicon::lexicon::*;
296    use alloc::collections::BTreeMap;
297    LexiconDoc {
298        lexicon: Lexicon::Lexicon1,
299        id: CowStr::new_static("network.slices.tools.bug.issue"),
300        defs: {
301            let mut map = BTreeMap::new();
302            map.insert(
303                SmolStr::new_static("main"),
304                LexUserType::Record(LexRecord {
305                    key: Some(CowStr::new_static("tid")),
306                    record: LexRecordRecord::Object(LexObject {
307                        required: Some(
308                            vec![
309                                SmolStr::new_static("bug"), SmolStr::new_static("issue"),
310                                SmolStr::new_static("createdAt")
311                            ],
312                        ),
313                        properties: {
314                            #[allow(unused_mut)]
315                            let mut map = BTreeMap::new();
316                            map.insert(
317                                SmolStr::new_static("bug"),
318                                LexObjectProperty::String(LexString {
319                                    description: Some(
320                                        CowStr::new_static("Reference to the bug report"),
321                                    ),
322                                    format: Some(LexStringFormat::AtUri),
323                                    ..Default::default()
324                                }),
325                            );
326                            map.insert(
327                                SmolStr::new_static("createdAt"),
328                                LexObjectProperty::String(LexString {
329                                    format: Some(LexStringFormat::Datetime),
330                                    ..Default::default()
331                                }),
332                            );
333                            map.insert(
334                                SmolStr::new_static("issue"),
335                                LexObjectProperty::String(LexString {
336                                    description: Some(
337                                        CowStr::new_static("Reference to the linked issue"),
338                                    ),
339                                    format: Some(LexStringFormat::AtUri),
340                                    ..Default::default()
341                                }),
342                            );
343                            map
344                        },
345                        ..Default::default()
346                    }),
347                    ..Default::default()
348                }),
349            );
350            map
351        },
352        ..Default::default()
353    }
354}