#[allow(unused_imports)]
use alloc::collections::BTreeMap;
use crate::sh_weaver::notebook::ReadingProgress;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::AtUri;
use jacquard_common::types::value::Data;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::IntoStatic;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct UpdateReadingProgress<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub current_entry: Option<AtUri<S>>,
pub notebook: AtUri<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub percent_complete: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<UpdateReadingProgressStatus<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum UpdateReadingProgressStatus<S: BosStr = DefaultStr> {
Reading,
Finished,
Abandoned,
WantToRead,
Other(S),
}
impl<S: BosStr> UpdateReadingProgressStatus<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Reading => "reading",
Self::Finished => "finished",
Self::Abandoned => "abandoned",
Self::WantToRead => "want-to-read",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"reading" => Self::Reading,
"finished" => Self::Finished,
"abandoned" => Self::Abandoned,
"want-to-read" => Self::WantToRead,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for UpdateReadingProgressStatus<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for UpdateReadingProgressStatus<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for UpdateReadingProgressStatus<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for UpdateReadingProgressStatus<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for UpdateReadingProgressStatus<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for UpdateReadingProgressStatus<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = UpdateReadingProgressStatus<S::Output>;
fn into_static(self) -> Self::Output {
match self {
UpdateReadingProgressStatus::Reading => UpdateReadingProgressStatus::Reading,
UpdateReadingProgressStatus::Finished => UpdateReadingProgressStatus::Finished,
UpdateReadingProgressStatus::Abandoned => UpdateReadingProgressStatus::Abandoned,
UpdateReadingProgressStatus::WantToRead => UpdateReadingProgressStatus::WantToRead,
UpdateReadingProgressStatus::Other(v) => {
UpdateReadingProgressStatus::Other(v.into_static())
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct UpdateReadingProgressOutput<S: BosStr = DefaultStr> {
pub progress: ReadingProgress<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
pub struct UpdateReadingProgressResponse;
impl jacquard_common::xrpc::XrpcResp for UpdateReadingProgressResponse {
const NSID: &'static str = "sh.weaver.notebook.updateReadingProgress";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = UpdateReadingProgressOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for UpdateReadingProgress<S> {
const NSID: &'static str = "sh.weaver.notebook.updateReadingProgress";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Response = UpdateReadingProgressResponse;
}
pub struct UpdateReadingProgressRequest;
impl jacquard_common::xrpc::XrpcEndpoint for UpdateReadingProgressRequest {
const PATH: &'static str = "/xrpc/sh.weaver.notebook.updateReadingProgress";
const METHOD: jacquard_common::xrpc::XrpcMethod =
jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
type Request<S: BosStr> = UpdateReadingProgress<S>;
type Response = UpdateReadingProgressResponse;
}
pub mod update_reading_progress_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Notebook;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Notebook = Unset;
}
pub struct SetNotebook<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetNotebook<St> {}
impl<St: State> State for SetNotebook<St> {
type Notebook = Set<members::notebook>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct notebook(());
}
}
pub struct UpdateReadingProgressBuilder<S: BosStr, St: update_reading_progress_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<AtUri<S>>,
Option<AtUri<S>>,
Option<i64>,
Option<UpdateReadingProgressStatus<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> UpdateReadingProgress<S> {
pub fn new() -> UpdateReadingProgressBuilder<S, update_reading_progress_state::Empty> {
UpdateReadingProgressBuilder::new()
}
}
impl<S: BosStr> UpdateReadingProgressBuilder<S, update_reading_progress_state::Empty> {
pub fn new() -> Self {
UpdateReadingProgressBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: update_reading_progress_state::State> UpdateReadingProgressBuilder<S, St> {
pub fn current_entry(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_current_entry(mut self, value: Option<AtUri<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> UpdateReadingProgressBuilder<S, St>
where
St: update_reading_progress_state::State,
St::Notebook: update_reading_progress_state::IsUnset,
{
pub fn notebook(
mut self,
value: impl Into<AtUri<S>>,
) -> UpdateReadingProgressBuilder<S, update_reading_progress_state::SetNotebook<St>> {
self._fields.1 = Option::Some(value.into());
UpdateReadingProgressBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: update_reading_progress_state::State> UpdateReadingProgressBuilder<S, St> {
pub fn percent_complete(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_percent_complete(mut self, value: Option<i64>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: update_reading_progress_state::State> UpdateReadingProgressBuilder<S, St> {
pub fn status(mut self, value: impl Into<Option<UpdateReadingProgressStatus<S>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_status(mut self, value: Option<UpdateReadingProgressStatus<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> UpdateReadingProgressBuilder<S, St>
where
St: update_reading_progress_state::State,
St::Notebook: update_reading_progress_state::IsSet,
{
pub fn build(self) -> UpdateReadingProgress<S> {
UpdateReadingProgress {
current_entry: self._fields.0,
notebook: self._fields.1.unwrap(),
percent_complete: self._fields.2,
status: self._fields.3,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> UpdateReadingProgress<S> {
UpdateReadingProgress {
current_entry: self._fields.0,
notebook: self._fields.1.unwrap(),
percent_complete: self._fields.2,
status: self._fields.3,
extra_data: Some(extra_data),
}
}
}