1#[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, UriValue};
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
30#[lexicon]
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(rename_all = "camelCase", rename = "blog.pckt.document", tag = "$type")]
33pub struct Document<'a> {
34 #[serde(borrow)]
35 pub document: StrongRef<'a>,
36 #[serde(borrow)]
37 pub site: UriValue<'a>,
38}
39
40#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
43#[serde(rename_all = "camelCase")]
44pub struct DocumentGetRecordOutput<'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: Document<'a>,
52}
53
54impl<'a> Document<'a> {
55 pub fn uri(
56 uri: impl Into<CowStr<'a>>,
57 ) -> Result<RecordUri<'a, DocumentRecord>, UriError> {
58 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
59 }
60}
61
62#[derive(Debug, Serialize, Deserialize)]
65pub struct DocumentRecord;
66impl XrpcResp for DocumentRecord {
67 const NSID: &'static str = "blog.pckt.document";
68 const ENCODING: &'static str = "application/json";
69 type Output<'de> = DocumentGetRecordOutput<'de>;
70 type Err<'de> = RecordError<'de>;
71}
72
73impl From<DocumentGetRecordOutput<'_>> for Document<'_> {
74 fn from(output: DocumentGetRecordOutput<'_>) -> Self {
75 use jacquard_common::IntoStatic;
76 output.value.into_static()
77 }
78}
79
80impl Collection for Document<'_> {
81 const NSID: &'static str = "blog.pckt.document";
82 type Record = DocumentRecord;
83}
84
85impl Collection for DocumentRecord {
86 const NSID: &'static str = "blog.pckt.document";
87 type Record = DocumentRecord;
88}
89
90impl<'a> LexiconSchema for Document<'a> {
91 fn nsid() -> &'static str {
92 "blog.pckt.document"
93 }
94 fn def_name() -> &'static str {
95 "main"
96 }
97 fn lexicon_doc() -> LexiconDoc<'static> {
98 lexicon_doc_blog_pckt_document()
99 }
100 fn validate(&self) -> Result<(), ConstraintError> {
101 Ok(())
102 }
103}
104
105pub mod document_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 pub trait State: sealed::Sealed {
115 type Document;
116 type Site;
117 }
118 pub struct Empty(());
120 impl sealed::Sealed for Empty {}
121 impl State for Empty {
122 type Document = Unset;
123 type Site = Unset;
124 }
125 pub struct SetDocument<S: State = Empty>(PhantomData<fn() -> S>);
127 impl<S: State> sealed::Sealed for SetDocument<S> {}
128 impl<S: State> State for SetDocument<S> {
129 type Document = Set<members::document>;
130 type Site = S::Site;
131 }
132 pub struct SetSite<S: State = Empty>(PhantomData<fn() -> S>);
134 impl<S: State> sealed::Sealed for SetSite<S> {}
135 impl<S: State> State for SetSite<S> {
136 type Document = S::Document;
137 type Site = Set<members::site>;
138 }
139 #[allow(non_camel_case_types)]
141 pub mod members {
142 pub struct document(());
144 pub struct site(());
146 }
147}
148
149pub struct DocumentBuilder<'a, S: document_state::State> {
151 _state: PhantomData<fn() -> S>,
152 _fields: (Option<StrongRef<'a>>, Option<UriValue<'a>>),
153 _lifetime: PhantomData<&'a ()>,
154}
155
156impl<'a> Document<'a> {
157 pub fn new() -> DocumentBuilder<'a, document_state::Empty> {
159 DocumentBuilder::new()
160 }
161}
162
163impl<'a> DocumentBuilder<'a, document_state::Empty> {
164 pub fn new() -> Self {
166 DocumentBuilder {
167 _state: PhantomData,
168 _fields: (None, None),
169 _lifetime: PhantomData,
170 }
171 }
172}
173
174impl<'a, S> DocumentBuilder<'a, S>
175where
176 S: document_state::State,
177 S::Document: document_state::IsUnset,
178{
179 pub fn document(
181 mut self,
182 value: impl Into<StrongRef<'a>>,
183 ) -> DocumentBuilder<'a, document_state::SetDocument<S>> {
184 self._fields.0 = Option::Some(value.into());
185 DocumentBuilder {
186 _state: PhantomData,
187 _fields: self._fields,
188 _lifetime: PhantomData,
189 }
190 }
191}
192
193impl<'a, S> DocumentBuilder<'a, S>
194where
195 S: document_state::State,
196 S::Site: document_state::IsUnset,
197{
198 pub fn site(
200 mut self,
201 value: impl Into<UriValue<'a>>,
202 ) -> DocumentBuilder<'a, document_state::SetSite<S>> {
203 self._fields.1 = Option::Some(value.into());
204 DocumentBuilder {
205 _state: PhantomData,
206 _fields: self._fields,
207 _lifetime: PhantomData,
208 }
209 }
210}
211
212impl<'a, S> DocumentBuilder<'a, S>
213where
214 S: document_state::State,
215 S::Document: document_state::IsSet,
216 S::Site: document_state::IsSet,
217{
218 pub fn build(self) -> Document<'a> {
220 Document {
221 document: self._fields.0.unwrap(),
222 site: self._fields.1.unwrap(),
223 extra_data: Default::default(),
224 }
225 }
226 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 ) -> Document<'a> {
234 Document {
235 document: self._fields.0.unwrap(),
236 site: self._fields.1.unwrap(),
237 extra_data: Some(extra_data),
238 }
239 }
240}
241
242fn lexicon_doc_blog_pckt_document() -> 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("blog.pckt.document"),
250 defs: {
251 let mut map = BTreeMap::new();
252 map.insert(
253 SmolStr::new_static("main"),
254 LexUserType::Record(LexRecord {
255 key: Some(CowStr::new_static("tid")),
256 record: LexRecordRecord::Object(LexObject {
257 required: Some(
258 vec![
259 SmolStr::new_static("document"), SmolStr::new_static("site")
260 ],
261 ),
262 properties: {
263 #[allow(unused_mut)]
264 let mut map = BTreeMap::new();
265 map.insert(
266 SmolStr::new_static("document"),
267 LexObjectProperty::Ref(LexRef {
268 r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
269 ..Default::default()
270 }),
271 );
272 map.insert(
273 SmolStr::new_static("site"),
274 LexObjectProperty::String(LexString {
275 format: Some(LexStringFormat::Uri),
276 ..Default::default()
277 }),
278 );
279 map
280 },
281 ..Default::default()
282 }),
283 ..Default::default()
284 }),
285 );
286 map
287 },
288 ..Default::default()
289 }
290}