Skip to main content

jacquard_api/app_bsky/graph/
block.rs

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