jacquard_api/pub_leaflet/poll/
vote.rs1#[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};
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#[lexicon]
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(rename_all = "camelCase", rename = "pub.leaflet.poll.vote", tag = "$type")]
34pub struct Vote<'a> {
35 #[serde(borrow)]
36 pub option: Vec<CowStr<'a>>,
37 #[serde(borrow)]
38 pub poll: StrongRef<'a>,
39}
40
41#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
44#[serde(rename_all = "camelCase")]
45pub struct VoteGetRecordOutput<'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: Vote<'a>,
53}
54
55impl<'a> Vote<'a> {
56 pub fn uri(
57 uri: impl Into<CowStr<'a>>,
58 ) -> Result<RecordUri<'a, VoteRecord>, UriError> {
59 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
60 }
61}
62
63#[derive(Debug, Serialize, Deserialize)]
66pub struct VoteRecord;
67impl XrpcResp for VoteRecord {
68 const NSID: &'static str = "pub.leaflet.poll.vote";
69 const ENCODING: &'static str = "application/json";
70 type Output<'de> = VoteGetRecordOutput<'de>;
71 type Err<'de> = RecordError<'de>;
72}
73
74impl From<VoteGetRecordOutput<'_>> for Vote<'_> {
75 fn from(output: VoteGetRecordOutput<'_>) -> Self {
76 use jacquard_common::IntoStatic;
77 output.value.into_static()
78 }
79}
80
81impl Collection for Vote<'_> {
82 const NSID: &'static str = "pub.leaflet.poll.vote";
83 type Record = VoteRecord;
84}
85
86impl Collection for VoteRecord {
87 const NSID: &'static str = "pub.leaflet.poll.vote";
88 type Record = VoteRecord;
89}
90
91impl<'a> LexiconSchema for Vote<'a> {
92 fn nsid() -> &'static str {
93 "pub.leaflet.poll.vote"
94 }
95 fn def_name() -> &'static str {
96 "main"
97 }
98 fn lexicon_doc() -> LexiconDoc<'static> {
99 lexicon_doc_pub_leaflet_poll_vote()
100 }
101 fn validate(&self) -> Result<(), ConstraintError> {
102 Ok(())
103 }
104}
105
106pub mod vote_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 pub trait State: sealed::Sealed {
116 type Option;
117 type Poll;
118 }
119 pub struct Empty(());
121 impl sealed::Sealed for Empty {}
122 impl State for Empty {
123 type Option = Unset;
124 type Poll = Unset;
125 }
126 pub struct SetOption<S: State = Empty>(PhantomData<fn() -> S>);
128 impl<S: State> sealed::Sealed for SetOption<S> {}
129 impl<S: State> State for SetOption<S> {
130 type Option = Set<members::option>;
131 type Poll = S::Poll;
132 }
133 pub struct SetPoll<S: State = Empty>(PhantomData<fn() -> S>);
135 impl<S: State> sealed::Sealed for SetPoll<S> {}
136 impl<S: State> State for SetPoll<S> {
137 type Option = S::Option;
138 type Poll = Set<members::poll>;
139 }
140 #[allow(non_camel_case_types)]
142 pub mod members {
143 pub struct option(());
145 pub struct poll(());
147 }
148}
149
150pub struct VoteBuilder<'a, S: vote_state::State> {
152 _state: PhantomData<fn() -> S>,
153 _fields: (Option<Vec<CowStr<'a>>>, Option<StrongRef<'a>>),
154 _lifetime: PhantomData<&'a ()>,
155}
156
157impl<'a> Vote<'a> {
158 pub fn new() -> VoteBuilder<'a, vote_state::Empty> {
160 VoteBuilder::new()
161 }
162}
163
164impl<'a> VoteBuilder<'a, vote_state::Empty> {
165 pub fn new() -> Self {
167 VoteBuilder {
168 _state: PhantomData,
169 _fields: (None, None),
170 _lifetime: PhantomData,
171 }
172 }
173}
174
175impl<'a, S> VoteBuilder<'a, S>
176where
177 S: vote_state::State,
178 S::Option: vote_state::IsUnset,
179{
180 pub fn option(
182 mut self,
183 value: impl Into<Vec<CowStr<'a>>>,
184 ) -> VoteBuilder<'a, vote_state::SetOption<S>> {
185 self._fields.0 = Option::Some(value.into());
186 VoteBuilder {
187 _state: PhantomData,
188 _fields: self._fields,
189 _lifetime: PhantomData,
190 }
191 }
192}
193
194impl<'a, S> VoteBuilder<'a, S>
195where
196 S: vote_state::State,
197 S::Poll: vote_state::IsUnset,
198{
199 pub fn poll(
201 mut self,
202 value: impl Into<StrongRef<'a>>,
203 ) -> VoteBuilder<'a, vote_state::SetPoll<S>> {
204 self._fields.1 = Option::Some(value.into());
205 VoteBuilder {
206 _state: PhantomData,
207 _fields: self._fields,
208 _lifetime: PhantomData,
209 }
210 }
211}
212
213impl<'a, S> VoteBuilder<'a, S>
214where
215 S: vote_state::State,
216 S::Option: vote_state::IsSet,
217 S::Poll: vote_state::IsSet,
218{
219 pub fn build(self) -> Vote<'a> {
221 Vote {
222 option: self._fields.0.unwrap(),
223 poll: self._fields.1.unwrap(),
224 extra_data: Default::default(),
225 }
226 }
227 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 ) -> Vote<'a> {
235 Vote {
236 option: self._fields.0.unwrap(),
237 poll: self._fields.1.unwrap(),
238 extra_data: Some(extra_data),
239 }
240 }
241}
242
243fn lexicon_doc_pub_leaflet_poll_vote() -> 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("pub.leaflet.poll.vote"),
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("Record declaring a vote on a poll"),
258 ),
259 key: Some(CowStr::new_static("tid")),
260 record: LexRecordRecord::Object(LexObject {
261 required: Some(
262 vec![
263 SmolStr::new_static("poll"), SmolStr::new_static("option")
264 ],
265 ),
266 properties: {
267 #[allow(unused_mut)]
268 let mut map = BTreeMap::new();
269 map.insert(
270 SmolStr::new_static("option"),
271 LexObjectProperty::Array(LexArray {
272 items: LexArrayItem::String(LexString {
273 ..Default::default()
274 }),
275 ..Default::default()
276 }),
277 );
278 map.insert(
279 SmolStr::new_static("poll"),
280 LexObjectProperty::Ref(LexRef {
281 r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
282 ..Default::default()
283 }),
284 );
285 map
286 },
287 ..Default::default()
288 }),
289 ..Default::default()
290 }),
291 );
292 map
293 },
294 ..Default::default()
295 }
296}