Skip to main content

jacquard_api/pub_leaflet/interactions/
recommend.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: pub.leaflet.interactions.recommend
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, Datetime};
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 representing a recommend on a document
29
30#[lexicon]
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(
33    rename_all = "camelCase",
34    rename = "pub.leaflet.interactions.recommend",
35    tag = "$type"
36)]
37pub struct Recommend<'a> {
38    pub created_at: Datetime,
39    #[serde(borrow)]
40    pub subject: AtUri<'a>,
41}
42
43/// Typed wrapper for GetRecord response with this collection's record type.
44
45#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
46#[serde(rename_all = "camelCase")]
47pub struct RecommendGetRecordOutput<'a> {
48    #[serde(skip_serializing_if = "Option::is_none")]
49    #[serde(borrow)]
50    pub cid: Option<Cid<'a>>,
51    #[serde(borrow)]
52    pub uri: AtUri<'a>,
53    #[serde(borrow)]
54    pub value: Recommend<'a>,
55}
56
57impl<'a> Recommend<'a> {
58    pub fn uri(
59        uri: impl Into<CowStr<'a>>,
60    ) -> Result<RecordUri<'a, RecommendRecord>, UriError> {
61        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
62    }
63}
64
65/// Marker type for deserializing records from this collection.
66
67#[derive(Debug, Serialize, Deserialize)]
68pub struct RecommendRecord;
69impl XrpcResp for RecommendRecord {
70    const NSID: &'static str = "pub.leaflet.interactions.recommend";
71    const ENCODING: &'static str = "application/json";
72    type Output<'de> = RecommendGetRecordOutput<'de>;
73    type Err<'de> = RecordError<'de>;
74}
75
76impl From<RecommendGetRecordOutput<'_>> for Recommend<'_> {
77    fn from(output: RecommendGetRecordOutput<'_>) -> Self {
78        use jacquard_common::IntoStatic;
79        output.value.into_static()
80    }
81}
82
83impl Collection for Recommend<'_> {
84    const NSID: &'static str = "pub.leaflet.interactions.recommend";
85    type Record = RecommendRecord;
86}
87
88impl Collection for RecommendRecord {
89    const NSID: &'static str = "pub.leaflet.interactions.recommend";
90    type Record = RecommendRecord;
91}
92
93impl<'a> LexiconSchema for Recommend<'a> {
94    fn nsid() -> &'static str {
95        "pub.leaflet.interactions.recommend"
96    }
97    fn def_name() -> &'static str {
98        "main"
99    }
100    fn lexicon_doc() -> LexiconDoc<'static> {
101        lexicon_doc_pub_leaflet_interactions_recommend()
102    }
103    fn validate(&self) -> Result<(), ConstraintError> {
104        Ok(())
105    }
106}
107
108pub mod recommend_state {
109
110    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
111    #[allow(unused)]
112    use ::core::marker::PhantomData;
113    mod sealed {
114        pub trait Sealed {}
115    }
116    /// State trait tracking which required fields have been set
117    pub trait State: sealed::Sealed {
118        type Subject;
119        type CreatedAt;
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 Subject = Unset;
126        type CreatedAt = Unset;
127    }
128    ///State transition - sets the `subject` field to Set
129    pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
130    impl<S: State> sealed::Sealed for SetSubject<S> {}
131    impl<S: State> State for SetSubject<S> {
132        type Subject = Set<members::subject>;
133        type CreatedAt = S::CreatedAt;
134    }
135    ///State transition - sets the `created_at` field to Set
136    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
137    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
138    impl<S: State> State for SetCreatedAt<S> {
139        type Subject = S::Subject;
140        type CreatedAt = Set<members::created_at>;
141    }
142    /// Marker types for field names
143    #[allow(non_camel_case_types)]
144    pub mod members {
145        ///Marker type for the `subject` field
146        pub struct subject(());
147        ///Marker type for the `created_at` field
148        pub struct created_at(());
149    }
150}
151
152/// Builder for constructing an instance of this type
153pub struct RecommendBuilder<'a, S: recommend_state::State> {
154    _state: PhantomData<fn() -> S>,
155    _fields: (Option<Datetime>, Option<AtUri<'a>>),
156    _lifetime: PhantomData<&'a ()>,
157}
158
159impl<'a> Recommend<'a> {
160    /// Create a new builder for this type
161    pub fn new() -> RecommendBuilder<'a, recommend_state::Empty> {
162        RecommendBuilder::new()
163    }
164}
165
166impl<'a> RecommendBuilder<'a, recommend_state::Empty> {
167    /// Create a new builder with all fields unset
168    pub fn new() -> Self {
169        RecommendBuilder {
170            _state: PhantomData,
171            _fields: (None, None),
172            _lifetime: PhantomData,
173        }
174    }
175}
176
177impl<'a, S> RecommendBuilder<'a, S>
178where
179    S: recommend_state::State,
180    S::CreatedAt: recommend_state::IsUnset,
181{
182    /// Set the `createdAt` field (required)
183    pub fn created_at(
184        mut self,
185        value: impl Into<Datetime>,
186    ) -> RecommendBuilder<'a, recommend_state::SetCreatedAt<S>> {
187        self._fields.0 = Option::Some(value.into());
188        RecommendBuilder {
189            _state: PhantomData,
190            _fields: self._fields,
191            _lifetime: PhantomData,
192        }
193    }
194}
195
196impl<'a, S> RecommendBuilder<'a, S>
197where
198    S: recommend_state::State,
199    S::Subject: recommend_state::IsUnset,
200{
201    /// Set the `subject` field (required)
202    pub fn subject(
203        mut self,
204        value: impl Into<AtUri<'a>>,
205    ) -> RecommendBuilder<'a, recommend_state::SetSubject<S>> {
206        self._fields.1 = Option::Some(value.into());
207        RecommendBuilder {
208            _state: PhantomData,
209            _fields: self._fields,
210            _lifetime: PhantomData,
211        }
212    }
213}
214
215impl<'a, S> RecommendBuilder<'a, S>
216where
217    S: recommend_state::State,
218    S::Subject: recommend_state::IsSet,
219    S::CreatedAt: recommend_state::IsSet,
220{
221    /// Build the final struct
222    pub fn build(self) -> Recommend<'a> {
223        Recommend {
224            created_at: self._fields.0.unwrap(),
225            subject: self._fields.1.unwrap(),
226            extra_data: Default::default(),
227        }
228    }
229    /// Build the final struct with custom extra_data
230    pub fn build_with_data(
231        self,
232        extra_data: BTreeMap<
233            jacquard_common::deps::smol_str::SmolStr,
234            jacquard_common::types::value::Data<'a>,
235        >,
236    ) -> Recommend<'a> {
237        Recommend {
238            created_at: self._fields.0.unwrap(),
239            subject: self._fields.1.unwrap(),
240            extra_data: Some(extra_data),
241        }
242    }
243}
244
245fn lexicon_doc_pub_leaflet_interactions_recommend() -> LexiconDoc<'static> {
246    #[allow(unused_imports)]
247    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
248    use jacquard_lexicon::lexicon::*;
249    use alloc::collections::BTreeMap;
250    LexiconDoc {
251        lexicon: Lexicon::Lexicon1,
252        id: CowStr::new_static("pub.leaflet.interactions.recommend"),
253        defs: {
254            let mut map = BTreeMap::new();
255            map.insert(
256                SmolStr::new_static("main"),
257                LexUserType::Record(LexRecord {
258                    description: Some(
259                        CowStr::new_static(
260                            "Record representing a recommend on a document",
261                        ),
262                    ),
263                    key: Some(CowStr::new_static("tid")),
264                    record: LexRecordRecord::Object(LexObject {
265                        required: Some(
266                            vec![
267                                SmolStr::new_static("subject"),
268                                SmolStr::new_static("createdAt")
269                            ],
270                        ),
271                        properties: {
272                            #[allow(unused_mut)]
273                            let mut map = BTreeMap::new();
274                            map.insert(
275                                SmolStr::new_static("createdAt"),
276                                LexObjectProperty::String(LexString {
277                                    format: Some(LexStringFormat::Datetime),
278                                    ..Default::default()
279                                }),
280                            );
281                            map.insert(
282                                SmolStr::new_static("subject"),
283                                LexObjectProperty::String(LexString {
284                                    format: Some(LexStringFormat::AtUri),
285                                    ..Default::default()
286                                }),
287                            );
288                            map
289                        },
290                        ..Default::default()
291                    }),
292                    ..Default::default()
293                }),
294            );
295            map
296        },
297        ..Default::default()
298    }
299}