Skip to main content

jacquard_api/sh_tangled/repo/issue/
state.rs

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