jacquard_api/sh_weaver/notebook/
update_reading_progress.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::AtUri;
15use jacquard_derive::{IntoStatic, lexicon};
16use serde::{Serialize, Deserialize};
17use crate::sh_weaver::notebook::ReadingProgress;
18
19#[lexicon]
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(rename_all = "camelCase")]
22pub struct UpdateReadingProgress<'a> {
23 #[serde(skip_serializing_if = "Option::is_none")]
25 #[serde(borrow)]
26 pub current_entry: Option<AtUri<'a>>,
27 #[serde(borrow)]
28 pub notebook: AtUri<'a>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub percent_complete: Option<i64>,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 #[serde(borrow)]
33 pub status: Option<UpdateReadingProgressStatus<'a>>,
34}
35
36
37#[derive(Debug, Clone, PartialEq, Eq, Hash)]
38pub enum UpdateReadingProgressStatus<'a> {
39 Reading,
40 Finished,
41 Abandoned,
42 WantToRead,
43 Other(CowStr<'a>),
44}
45
46impl<'a> UpdateReadingProgressStatus<'a> {
47 pub fn as_str(&self) -> &str {
48 match self {
49 Self::Reading => "reading",
50 Self::Finished => "finished",
51 Self::Abandoned => "abandoned",
52 Self::WantToRead => "want-to-read",
53 Self::Other(s) => s.as_ref(),
54 }
55 }
56}
57
58impl<'a> From<&'a str> for UpdateReadingProgressStatus<'a> {
59 fn from(s: &'a str) -> Self {
60 match s {
61 "reading" => Self::Reading,
62 "finished" => Self::Finished,
63 "abandoned" => Self::Abandoned,
64 "want-to-read" => Self::WantToRead,
65 _ => Self::Other(CowStr::from(s)),
66 }
67 }
68}
69
70impl<'a> From<String> for UpdateReadingProgressStatus<'a> {
71 fn from(s: String) -> Self {
72 match s.as_str() {
73 "reading" => Self::Reading,
74 "finished" => Self::Finished,
75 "abandoned" => Self::Abandoned,
76 "want-to-read" => Self::WantToRead,
77 _ => Self::Other(CowStr::from(s)),
78 }
79 }
80}
81
82impl<'a> core::fmt::Display for UpdateReadingProgressStatus<'a> {
83 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
84 write!(f, "{}", self.as_str())
85 }
86}
87
88impl<'a> AsRef<str> for UpdateReadingProgressStatus<'a> {
89 fn as_ref(&self) -> &str {
90 self.as_str()
91 }
92}
93
94impl<'a> serde::Serialize for UpdateReadingProgressStatus<'a> {
95 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
96 where
97 S: serde::Serializer,
98 {
99 serializer.serialize_str(self.as_str())
100 }
101}
102
103impl<'de, 'a> serde::Deserialize<'de> for UpdateReadingProgressStatus<'a>
104where
105 'de: 'a,
106{
107 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
108 where
109 D: serde::Deserializer<'de>,
110 {
111 let s = <&'de str>::deserialize(deserializer)?;
112 Ok(Self::from(s))
113 }
114}
115
116impl<'a> Default for UpdateReadingProgressStatus<'a> {
117 fn default() -> Self {
118 Self::Other(Default::default())
119 }
120}
121
122impl jacquard_common::IntoStatic for UpdateReadingProgressStatus<'_> {
123 type Output = UpdateReadingProgressStatus<'static>;
124 fn into_static(self) -> Self::Output {
125 match self {
126 UpdateReadingProgressStatus::Reading => UpdateReadingProgressStatus::Reading,
127 UpdateReadingProgressStatus::Finished => {
128 UpdateReadingProgressStatus::Finished
129 }
130 UpdateReadingProgressStatus::Abandoned => {
131 UpdateReadingProgressStatus::Abandoned
132 }
133 UpdateReadingProgressStatus::WantToRead => {
134 UpdateReadingProgressStatus::WantToRead
135 }
136 UpdateReadingProgressStatus::Other(v) => {
137 UpdateReadingProgressStatus::Other(v.into_static())
138 }
139 }
140 }
141}
142
143
144#[lexicon]
145#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
146#[serde(rename_all = "camelCase")]
147pub struct UpdateReadingProgressOutput<'a> {
148 #[serde(borrow)]
149 pub progress: ReadingProgress<'a>,
150}
151
152pub struct UpdateReadingProgressResponse;
154impl jacquard_common::xrpc::XrpcResp for UpdateReadingProgressResponse {
155 const NSID: &'static str = "sh.weaver.notebook.updateReadingProgress";
156 const ENCODING: &'static str = "application/json";
157 type Output<'de> = UpdateReadingProgressOutput<'de>;
158 type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
159}
160
161impl<'a> jacquard_common::xrpc::XrpcRequest for UpdateReadingProgress<'a> {
162 const NSID: &'static str = "sh.weaver.notebook.updateReadingProgress";
163 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
164 "application/json",
165 );
166 type Response = UpdateReadingProgressResponse;
167}
168
169pub struct UpdateReadingProgressRequest;
171impl jacquard_common::xrpc::XrpcEndpoint for UpdateReadingProgressRequest {
172 const PATH: &'static str = "/xrpc/sh.weaver.notebook.updateReadingProgress";
173 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
174 "application/json",
175 );
176 type Request<'de> = UpdateReadingProgress<'de>;
177 type Response = UpdateReadingProgressResponse;
178}
179
180pub mod update_reading_progress_state {
181
182 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
183 #[allow(unused)]
184 use ::core::marker::PhantomData;
185 mod sealed {
186 pub trait Sealed {}
187 }
188 pub trait State: sealed::Sealed {
190 type Notebook;
191 }
192 pub struct Empty(());
194 impl sealed::Sealed for Empty {}
195 impl State for Empty {
196 type Notebook = Unset;
197 }
198 pub struct SetNotebook<S: State = Empty>(PhantomData<fn() -> S>);
200 impl<S: State> sealed::Sealed for SetNotebook<S> {}
201 impl<S: State> State for SetNotebook<S> {
202 type Notebook = Set<members::notebook>;
203 }
204 #[allow(non_camel_case_types)]
206 pub mod members {
207 pub struct notebook(());
209 }
210}
211
212pub struct UpdateReadingProgressBuilder<'a, S: update_reading_progress_state::State> {
214 _state: PhantomData<fn() -> S>,
215 _fields: (
216 Option<AtUri<'a>>,
217 Option<AtUri<'a>>,
218 Option<i64>,
219 Option<UpdateReadingProgressStatus<'a>>,
220 ),
221 _lifetime: PhantomData<&'a ()>,
222}
223
224impl<'a> UpdateReadingProgress<'a> {
225 pub fn new() -> UpdateReadingProgressBuilder<
227 'a,
228 update_reading_progress_state::Empty,
229 > {
230 UpdateReadingProgressBuilder::new()
231 }
232}
233
234impl<'a> UpdateReadingProgressBuilder<'a, update_reading_progress_state::Empty> {
235 pub fn new() -> Self {
237 UpdateReadingProgressBuilder {
238 _state: PhantomData,
239 _fields: (None, None, None, None),
240 _lifetime: PhantomData,
241 }
242 }
243}
244
245impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> {
246 pub fn current_entry(mut self, value: impl Into<Option<AtUri<'a>>>) -> Self {
248 self._fields.0 = value.into();
249 self
250 }
251 pub fn maybe_current_entry(mut self, value: Option<AtUri<'a>>) -> Self {
253 self._fields.0 = value;
254 self
255 }
256}
257
258impl<'a, S> UpdateReadingProgressBuilder<'a, S>
259where
260 S: update_reading_progress_state::State,
261 S::Notebook: update_reading_progress_state::IsUnset,
262{
263 pub fn notebook(
265 mut self,
266 value: impl Into<AtUri<'a>>,
267 ) -> UpdateReadingProgressBuilder<
268 'a,
269 update_reading_progress_state::SetNotebook<S>,
270 > {
271 self._fields.1 = Option::Some(value.into());
272 UpdateReadingProgressBuilder {
273 _state: PhantomData,
274 _fields: self._fields,
275 _lifetime: PhantomData,
276 }
277 }
278}
279
280impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> {
281 pub fn percent_complete(mut self, value: impl Into<Option<i64>>) -> Self {
283 self._fields.2 = value.into();
284 self
285 }
286 pub fn maybe_percent_complete(mut self, value: Option<i64>) -> Self {
288 self._fields.2 = value;
289 self
290 }
291}
292
293impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> {
294 pub fn status(
296 mut self,
297 value: impl Into<Option<UpdateReadingProgressStatus<'a>>>,
298 ) -> Self {
299 self._fields.3 = value.into();
300 self
301 }
302 pub fn maybe_status(
304 mut self,
305 value: Option<UpdateReadingProgressStatus<'a>>,
306 ) -> Self {
307 self._fields.3 = value;
308 self
309 }
310}
311
312impl<'a, S> UpdateReadingProgressBuilder<'a, S>
313where
314 S: update_reading_progress_state::State,
315 S::Notebook: update_reading_progress_state::IsSet,
316{
317 pub fn build(self) -> UpdateReadingProgress<'a> {
319 UpdateReadingProgress {
320 current_entry: self._fields.0,
321 notebook: self._fields.1.unwrap(),
322 percent_complete: self._fields.2,
323 status: self._fields.3,
324 extra_data: Default::default(),
325 }
326 }
327 pub fn build_with_data(
329 self,
330 extra_data: BTreeMap<
331 jacquard_common::deps::smol_str::SmolStr,
332 jacquard_common::types::value::Data<'a>,
333 >,
334 ) -> UpdateReadingProgress<'a> {
335 UpdateReadingProgress {
336 current_entry: self._fields.0,
337 notebook: self._fields.1.unwrap(),
338 percent_complete: self._fields.2,
339 status: self._fields.3,
340 extra_data: Some(extra_data),
341 }
342 }
343}