jacquard-api 0.10.2

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

#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct GetBook<'a> {
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub goodreads_id: std::option::Option<jacquard_common::CowStr<'a>>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub id: std::option::Option<jacquard_common::CowStr<'a>>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub isbn: std::option::Option<jacquard_common::CowStr<'a>>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub isbn13: std::option::Option<jacquard_common::CowStr<'a>>,
}

pub mod get_book_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 {}
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {}
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {}
}

/// Builder for constructing an instance of this type
pub struct GetBookBuilder<'a, S: get_book_state::State> {
    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
    __unsafe_private_named: (
        ::core::option::Option<jacquard_common::CowStr<'a>>,
        ::core::option::Option<jacquard_common::CowStr<'a>>,
        ::core::option::Option<jacquard_common::CowStr<'a>>,
        ::core::option::Option<jacquard_common::CowStr<'a>>,
    ),
    _phantom: ::core::marker::PhantomData<&'a ()>,
}

impl<'a> GetBook<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetBookBuilder<'a, get_book_state::Empty> {
        GetBookBuilder::new()
    }
}

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

impl<'a, S: get_book_state::State> GetBookBuilder<'a, S> {
    /// Set the `goodreadsId` field (optional)
    pub fn goodreads_id(
        mut self,
        value: impl Into<Option<jacquard_common::CowStr<'a>>>,
    ) -> Self {
        self.__unsafe_private_named.0 = value.into();
        self
    }
    /// Set the `goodreadsId` field to an Option value (optional)
    pub fn maybe_goodreads_id(
        mut self,
        value: Option<jacquard_common::CowStr<'a>>,
    ) -> Self {
        self.__unsafe_private_named.0 = value;
        self
    }
}

impl<'a, S: get_book_state::State> GetBookBuilder<'a, S> {
    /// Set the `id` field (optional)
    pub fn id(mut self, value: impl Into<Option<jacquard_common::CowStr<'a>>>) -> Self {
        self.__unsafe_private_named.1 = value.into();
        self
    }
    /// Set the `id` field to an Option value (optional)
    pub fn maybe_id(mut self, value: Option<jacquard_common::CowStr<'a>>) -> Self {
        self.__unsafe_private_named.1 = value;
        self
    }
}

impl<'a, S: get_book_state::State> GetBookBuilder<'a, S> {
    /// Set the `isbn` field (optional)
    pub fn isbn(
        mut self,
        value: impl Into<Option<jacquard_common::CowStr<'a>>>,
    ) -> Self {
        self.__unsafe_private_named.2 = value.into();
        self
    }
    /// Set the `isbn` field to an Option value (optional)
    pub fn maybe_isbn(mut self, value: Option<jacquard_common::CowStr<'a>>) -> Self {
        self.__unsafe_private_named.2 = value;
        self
    }
}

impl<'a, S: get_book_state::State> GetBookBuilder<'a, S> {
    /// Set the `isbn13` field (optional)
    pub fn isbn13(
        mut self,
        value: impl Into<Option<jacquard_common::CowStr<'a>>>,
    ) -> Self {
        self.__unsafe_private_named.3 = value.into();
        self
    }
    /// Set the `isbn13` field to an Option value (optional)
    pub fn maybe_isbn13(mut self, value: Option<jacquard_common::CowStr<'a>>) -> Self {
        self.__unsafe_private_named.3 = value;
        self
    }
}

impl<'a, S> GetBookBuilder<'a, S>
where
    S: get_book_state::State,
{
    /// Build the final struct
    pub fn build(self) -> GetBook<'a> {
        GetBook {
            goodreads_id: self.__unsafe_private_named.0,
            id: self.__unsafe_private_named.1,
            isbn: self.__unsafe_private_named.2,
            isbn13: self.__unsafe_private_named.3,
        }
    }
}

#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct GetBookOutput<'a> {
    ///Other users' activity on the book
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub activity: std::option::Option<Vec<crate::buzz_bookhive::Activity<'a>>>,
    ///The hive book's info
    #[serde(borrow)]
    pub book: crate::buzz_bookhive::hive_book::HiveBook<'a>,
    ///Reading progress for the user
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub book_progress: std::option::Option<crate::buzz_bookhive::BookProgress<'a>>,
    ///Comments on the book
    #[serde(borrow)]
    pub comments: Vec<crate::buzz_bookhive::Comment<'a>>,
    ///Cover image of the book
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub cover: std::option::Option<jacquard_common::types::blob::BlobRef<'a>>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub created_at: std::option::Option<jacquard_common::types::string::Datetime>,
    ///The date the user finished reading the book
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub finished_at: std::option::Option<jacquard_common::types::string::Datetime>,
    ///The book's review
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub review: std::option::Option<jacquard_common::CowStr<'a>>,
    ///Reviews of the book
    #[serde(borrow)]
    pub reviews: Vec<crate::buzz_bookhive::Review<'a>>,
    ///Number of stars given to the book (1-10) which will be mapped to 1-5 stars
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub stars: std::option::Option<i64>,
    ///The date the user started reading the book
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub started_at: std::option::Option<jacquard_common::types::string::Datetime>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub status: std::option::Option<GetBookOutputStatus<'a>>,
}

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

impl<'a> GetBookOutputStatus<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Finished => "buzz.bookhive.defs#finished",
            Self::Reading => "buzz.bookhive.defs#reading",
            Self::WantToRead => "buzz.bookhive.defs#wantToRead",
            Self::Abandoned => "buzz.bookhive.defs#abandoned",
            Self::Owned => "buzz.bookhive.defs#owned",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for GetBookOutputStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "buzz.bookhive.defs#finished" => Self::Finished,
            "buzz.bookhive.defs#reading" => Self::Reading,
            "buzz.bookhive.defs#wantToRead" => Self::WantToRead,
            "buzz.bookhive.defs#abandoned" => Self::Abandoned,
            "buzz.bookhive.defs#owned" => Self::Owned,
            _ => Self::Other(jacquard_common::CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for GetBookOutputStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "buzz.bookhive.defs#finished" => Self::Finished,
            "buzz.bookhive.defs#reading" => Self::Reading,
            "buzz.bookhive.defs#wantToRead" => Self::WantToRead,
            "buzz.bookhive.defs#abandoned" => Self::Abandoned,
            "buzz.bookhive.defs#owned" => Self::Owned,
            _ => Self::Other(jacquard_common::CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for GetBookOutputStatus<'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 GetBookOutputStatus<'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 GetBookOutputStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for GetBookOutputStatus<'_> {
    type Output = GetBookOutputStatus<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            GetBookOutputStatus::Finished => GetBookOutputStatus::Finished,
            GetBookOutputStatus::Reading => GetBookOutputStatus::Reading,
            GetBookOutputStatus::WantToRead => GetBookOutputStatus::WantToRead,
            GetBookOutputStatus::Abandoned => GetBookOutputStatus::Abandoned,
            GetBookOutputStatus::Owned => GetBookOutputStatus::Owned,
            GetBookOutputStatus::Other(v) => GetBookOutputStatus::Other(v.into_static()),
        }
    }
}

/// Response type for
///buzz.bookhive.getBook
pub struct GetBookResponse;
impl jacquard_common::xrpc::XrpcResp for GetBookResponse {
    const NSID: &'static str = "buzz.bookhive.getBook";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetBookOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetBook<'a> {
    const NSID: &'static str = "buzz.bookhive.getBook";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetBookResponse;
}

/// Endpoint type for
///buzz.bookhive.getBook
pub struct GetBookRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetBookRequest {
    const PATH: &'static str = "/xrpc/buzz.bookhive.getBook";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetBook<'de>;
    type Response = GetBookResponse;
}