jacquard_api/place_stream/chat/
gate.rs1#[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#[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 #[serde(borrow)]
36 pub hidden_message: AtUri<'a>,
37}
38
39#[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#[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 pub trait State: sealed::Sealed {
114 type HiddenMessage;
115 }
116 pub struct Empty(());
118 impl sealed::Sealed for Empty {}
119 impl State for Empty {
120 type HiddenMessage = Unset;
121 }
122 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 #[allow(non_camel_case_types)]
130 pub mod members {
131 pub struct hidden_message(());
133 }
134}
135
136pub 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 pub fn new() -> GateBuilder<'a, gate_state::Empty> {
146 GateBuilder::new()
147 }
148}
149
150impl<'a> GateBuilder<'a, gate_state::Empty> {
151 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 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 pub fn build(self) -> Gate<'a> {
187 Gate {
188 hidden_message: self._fields.0.unwrap(),
189 extra_data: Default::default(),
190 }
191 }
192 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}