Skip to main content

jacquard_api/place_stream/chat/
gate.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.chat.gate
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;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::types::collection::{Collection, RecordError};
18use jacquard_common::types::string::{AtUri, Cid};
19use jacquard_common::types::uri::{RecordUri, UriError};
20use jacquard_common::xrpc::XrpcResp;
21use jacquard_derive::{IntoStatic, lexicon};
22use jacquard_lexicon::lexicon::LexiconDoc;
23use jacquard_lexicon::schema::LexiconSchema;
24
25#[allow(unused_imports)]
26use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
27use serde::{Serialize, Deserialize};
28/// Record defining a single gated chat message.
29
30#[lexicon]
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(rename_all = "camelCase", rename = "place.stream.chat.gate", tag = "$type")]
33pub struct Gate<'a> {
34    ///URI of the hidden chat message.
35    #[serde(borrow)]
36    pub hidden_message: AtUri<'a>,
37}
38
39/// Typed wrapper for GetRecord response with this collection's record type.
40
41#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
42#[serde(rename_all = "camelCase")]
43pub struct GateGetRecordOutput<'a> {
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[serde(borrow)]
46    pub cid: Option<Cid<'a>>,
47    #[serde(borrow)]
48    pub uri: AtUri<'a>,
49    #[serde(borrow)]
50    pub value: Gate<'a>,
51}
52
53impl<'a> Gate<'a> {
54    pub fn uri(
55        uri: impl Into<CowStr<'a>>,
56    ) -> Result<RecordUri<'a, GateRecord>, UriError> {
57        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
58    }
59}
60
61/// Marker type for deserializing records from this collection.
62
63#[derive(Debug, Serialize, Deserialize)]
64pub struct GateRecord;
65impl XrpcResp for GateRecord {
66    const NSID: &'static str = "place.stream.chat.gate";
67    const ENCODING: &'static str = "application/json";
68    type Output<'de> = GateGetRecordOutput<'de>;
69    type Err<'de> = RecordError<'de>;
70}
71
72impl From<GateGetRecordOutput<'_>> for Gate<'_> {
73    fn from(output: GateGetRecordOutput<'_>) -> Self {
74        use jacquard_common::IntoStatic;
75        output.value.into_static()
76    }
77}
78
79impl Collection for Gate<'_> {
80    const NSID: &'static str = "place.stream.chat.gate";
81    type Record = GateRecord;
82}
83
84impl Collection for GateRecord {
85    const NSID: &'static str = "place.stream.chat.gate";
86    type Record = GateRecord;
87}
88
89impl<'a> LexiconSchema for Gate<'a> {
90    fn nsid() -> &'static str {
91        "place.stream.chat.gate"
92    }
93    fn def_name() -> &'static str {
94        "main"
95    }
96    fn lexicon_doc() -> LexiconDoc<'static> {
97        lexicon_doc_place_stream_chat_gate()
98    }
99    fn validate(&self) -> Result<(), ConstraintError> {
100        Ok(())
101    }
102}
103
104pub mod gate_state {
105
106    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
107    #[allow(unused)]
108    use ::core::marker::PhantomData;
109    mod sealed {
110        pub trait Sealed {}
111    }
112    /// State trait tracking which required fields have been set
113    pub trait State: sealed::Sealed {
114        type HiddenMessage;
115    }
116    /// Empty state - all required fields are unset
117    pub struct Empty(());
118    impl sealed::Sealed for Empty {}
119    impl State for Empty {
120        type HiddenMessage = Unset;
121    }
122    ///State transition - sets the `hidden_message` field to Set
123    pub struct SetHiddenMessage<S: State = Empty>(PhantomData<fn() -> S>);
124    impl<S: State> sealed::Sealed for SetHiddenMessage<S> {}
125    impl<S: State> State for SetHiddenMessage<S> {
126        type HiddenMessage = Set<members::hidden_message>;
127    }
128    /// Marker types for field names
129    #[allow(non_camel_case_types)]
130    pub mod members {
131        ///Marker type for the `hidden_message` field
132        pub struct hidden_message(());
133    }
134}
135
136/// Builder for constructing an instance of this type
137pub struct GateBuilder<'a, S: gate_state::State> {
138    _state: PhantomData<fn() -> S>,
139    _fields: (Option<AtUri<'a>>,),
140    _lifetime: PhantomData<&'a ()>,
141}
142
143impl<'a> Gate<'a> {
144    /// Create a new builder for this type
145    pub fn new() -> GateBuilder<'a, gate_state::Empty> {
146        GateBuilder::new()
147    }
148}
149
150impl<'a> GateBuilder<'a, gate_state::Empty> {
151    /// Create a new builder with all fields unset
152    pub fn new() -> Self {
153        GateBuilder {
154            _state: PhantomData,
155            _fields: (None,),
156            _lifetime: PhantomData,
157        }
158    }
159}
160
161impl<'a, S> GateBuilder<'a, S>
162where
163    S: gate_state::State,
164    S::HiddenMessage: gate_state::IsUnset,
165{
166    /// Set the `hiddenMessage` field (required)
167    pub fn hidden_message(
168        mut self,
169        value: impl Into<AtUri<'a>>,
170    ) -> GateBuilder<'a, gate_state::SetHiddenMessage<S>> {
171        self._fields.0 = Option::Some(value.into());
172        GateBuilder {
173            _state: PhantomData,
174            _fields: self._fields,
175            _lifetime: PhantomData,
176        }
177    }
178}
179
180impl<'a, S> GateBuilder<'a, S>
181where
182    S: gate_state::State,
183    S::HiddenMessage: gate_state::IsSet,
184{
185    /// Build the final struct
186    pub fn build(self) -> Gate<'a> {
187        Gate {
188            hidden_message: self._fields.0.unwrap(),
189            extra_data: Default::default(),
190        }
191    }
192    /// Build the final struct with custom extra_data
193    pub fn build_with_data(
194        self,
195        extra_data: BTreeMap<
196            jacquard_common::deps::smol_str::SmolStr,
197            jacquard_common::types::value::Data<'a>,
198        >,
199    ) -> Gate<'a> {
200        Gate {
201            hidden_message: self._fields.0.unwrap(),
202            extra_data: Some(extra_data),
203        }
204    }
205}
206
207fn lexicon_doc_place_stream_chat_gate() -> LexiconDoc<'static> {
208    #[allow(unused_imports)]
209    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
210    use jacquard_lexicon::lexicon::*;
211    use alloc::collections::BTreeMap;
212    LexiconDoc {
213        lexicon: Lexicon::Lexicon1,
214        id: CowStr::new_static("place.stream.chat.gate"),
215        defs: {
216            let mut map = BTreeMap::new();
217            map.insert(
218                SmolStr::new_static("main"),
219                LexUserType::Record(LexRecord {
220                    description: Some(
221                        CowStr::new_static(
222                            "Record defining a single gated chat message.",
223                        ),
224                    ),
225                    key: Some(CowStr::new_static("tid")),
226                    record: LexRecordRecord::Object(LexObject {
227                        required: Some(vec![SmolStr::new_static("hiddenMessage")]),
228                        properties: {
229                            #[allow(unused_mut)]
230                            let mut map = BTreeMap::new();
231                            map.insert(
232                                SmolStr::new_static("hiddenMessage"),
233                                LexObjectProperty::String(LexString {
234                                    description: Some(
235                                        CowStr::new_static("URI of the hidden chat message."),
236                                    ),
237                                    format: Some(LexStringFormat::AtUri),
238                                    ..Default::default()
239                                }),
240                            );
241                            map
242                        },
243                        ..Default::default()
244                    }),
245                    ..Default::default()
246                }),
247            );
248            map
249        },
250        ..Default::default()
251    }
252}