Skip to main content

jacquard_api/sh_weaver/graph/
like.rs

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