jacquard-api 0.10.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.notebook.updateReadingProgress
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct UpdateReadingProgress<'a> {
    ///The entry the user is currently on.
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub current_entry: std::option::Option<jacquard_common::types::string::AtUri<'a>>,
    #[serde(borrow)]
    pub notebook: jacquard_common::types::string::AtUri<'a>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub percent_complete: std::option::Option<i64>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub status: std::option::Option<UpdateReadingProgressStatus<'a>>,
}

pub mod update_reading_progress_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Notebook;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Notebook = Unset;
    }
    ///State transition - sets the `notebook` field to Set
    pub struct SetNotebook<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetNotebook<S> {}
    impl<S: State> State for SetNotebook<S> {
        type Notebook = Set<members::notebook>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `notebook` field
        pub struct notebook(());
    }
}

/// Builder for constructing an instance of this type
pub struct UpdateReadingProgressBuilder<'a, S: update_reading_progress_state::State> {
    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
    __unsafe_private_named: (
        ::core::option::Option<jacquard_common::types::string::AtUri<'a>>,
        ::core::option::Option<jacquard_common::types::string::AtUri<'a>>,
        ::core::option::Option<i64>,
        ::core::option::Option<UpdateReadingProgressStatus<'a>>,
    ),
    _phantom: ::core::marker::PhantomData<&'a ()>,
}

impl<'a> UpdateReadingProgress<'a> {
    /// Create a new builder for this type
    pub fn new() -> UpdateReadingProgressBuilder<
        'a,
        update_reading_progress_state::Empty,
    > {
        UpdateReadingProgressBuilder::new()
    }
}

impl<'a> UpdateReadingProgressBuilder<'a, update_reading_progress_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        UpdateReadingProgressBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: (None, None, None, None),
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> {
    /// Set the `currentEntry` field (optional)
    pub fn current_entry(
        mut self,
        value: impl Into<Option<jacquard_common::types::string::AtUri<'a>>>,
    ) -> Self {
        self.__unsafe_private_named.0 = value.into();
        self
    }
    /// Set the `currentEntry` field to an Option value (optional)
    pub fn maybe_current_entry(
        mut self,
        value: Option<jacquard_common::types::string::AtUri<'a>>,
    ) -> Self {
        self.__unsafe_private_named.0 = value;
        self
    }
}

impl<'a, S> UpdateReadingProgressBuilder<'a, S>
where
    S: update_reading_progress_state::State,
    S::Notebook: update_reading_progress_state::IsUnset,
{
    /// Set the `notebook` field (required)
    pub fn notebook(
        mut self,
        value: impl Into<jacquard_common::types::string::AtUri<'a>>,
    ) -> UpdateReadingProgressBuilder<
        'a,
        update_reading_progress_state::SetNotebook<S>,
    > {
        self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
        UpdateReadingProgressBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: self.__unsafe_private_named,
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> {
    /// Set the `percentComplete` field (optional)
    pub fn percent_complete(mut self, value: impl Into<Option<i64>>) -> Self {
        self.__unsafe_private_named.2 = value.into();
        self
    }
    /// Set the `percentComplete` field to an Option value (optional)
    pub fn maybe_percent_complete(mut self, value: Option<i64>) -> Self {
        self.__unsafe_private_named.2 = value;
        self
    }
}

impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> {
    /// Set the `status` field (optional)
    pub fn status(
        mut self,
        value: impl Into<Option<UpdateReadingProgressStatus<'a>>>,
    ) -> Self {
        self.__unsafe_private_named.3 = value.into();
        self
    }
    /// Set the `status` field to an Option value (optional)
    pub fn maybe_status(
        mut self,
        value: Option<UpdateReadingProgressStatus<'a>>,
    ) -> Self {
        self.__unsafe_private_named.3 = value;
        self
    }
}

impl<'a, S> UpdateReadingProgressBuilder<'a, S>
where
    S: update_reading_progress_state::State,
    S::Notebook: update_reading_progress_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> UpdateReadingProgress<'a> {
        UpdateReadingProgress {
            current_entry: self.__unsafe_private_named.0,
            notebook: self.__unsafe_private_named.1.unwrap(),
            percent_complete: self.__unsafe_private_named.2,
            status: self.__unsafe_private_named.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: std::collections::BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> UpdateReadingProgress<'a> {
        UpdateReadingProgress {
            current_entry: self.__unsafe_private_named.0,
            notebook: self.__unsafe_private_named.1.unwrap(),
            percent_complete: self.__unsafe_private_named.2,
            status: self.__unsafe_private_named.3,
            extra_data: Some(extra_data),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum UpdateReadingProgressStatus<'a> {
    Reading,
    Finished,
    Abandoned,
    WantToRead,
    Other(jacquard_common::CowStr<'a>),
}

impl<'a> UpdateReadingProgressStatus<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for UpdateReadingProgressStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "reading" => Self::Reading,
            "finished" => Self::Finished,
            "abandoned" => Self::Abandoned,
            "want-to-read" => Self::WantToRead,
            _ => Self::Other(jacquard_common::CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for UpdateReadingProgressStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "reading" => Self::Reading,
            "finished" => Self::Finished,
            "abandoned" => Self::Abandoned,
            "want-to-read" => Self::WantToRead,
            _ => Self::Other(jacquard_common::CowStr::from(s)),
        }
    }
}

impl<'a> core::fmt::Display for UpdateReadingProgressStatus<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> AsRef<str> for UpdateReadingProgressStatus<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for UpdateReadingProgressStatus<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for UpdateReadingProgressStatus<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for UpdateReadingProgressStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for UpdateReadingProgressStatus<'_> {
    type Output = UpdateReadingProgressStatus<'static>;
    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())
            }
        }
    }
}

#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct UpdateReadingProgressOutput<'a> {
    #[serde(borrow)]
    pub progress: crate::sh_weaver::notebook::ReadingProgress<'a>,
}

/// Response type for
///sh.weaver.notebook.updateReadingProgress
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<'de> = UpdateReadingProgressOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for UpdateReadingProgress<'a> {
    const NSID: &'static str = "sh.weaver.notebook.updateReadingProgress";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = UpdateReadingProgressResponse;
}

/// Endpoint type for
///sh.weaver.notebook.updateReadingProgress
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<'de> = UpdateReadingProgress<'de>;
    type Response = UpdateReadingProgressResponse;
}