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