#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::string::Datetime;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::buzz_bookhive::Activity;
use crate::buzz_bookhive::BookProgress;
use crate::buzz_bookhive::Comment;
use crate::buzz_bookhive::Review;
use crate::buzz_bookhive::hive_book::HiveBook;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetBook<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub goodreads_id: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub id: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub isbn: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub isbn13: Option<CowStr<'a>>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetBookOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub activity: Option<Vec<Activity<'a>>>,
#[serde(borrow)]
pub book: HiveBook<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub book_progress: Option<BookProgress<'a>>,
#[serde(borrow)]
pub comments: Vec<Comment<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cover: Option<BlobRef<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub finished_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub review: Option<CowStr<'a>>,
#[serde(borrow)]
pub reviews: Vec<Review<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stars: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub started_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub status: Option<GetBookOutputStatus<'a>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GetBookOutputStatus<'a> {
Finished,
Reading,
WantToRead,
Abandoned,
Owned,
Other(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(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(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()),
}
}
}
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;
}
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;
}
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 {}
}
pub trait State: sealed::Sealed {}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {}
#[allow(non_camel_case_types)]
pub mod members {}
}
pub struct GetBookBuilder<'a, S: get_book_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> GetBook<'a> {
pub fn new() -> GetBookBuilder<'a, get_book_state::Empty> {
GetBookBuilder::new()
}
}
impl<'a> GetBookBuilder<'a, get_book_state::Empty> {
pub fn new() -> Self {
GetBookBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: get_book_state::State> GetBookBuilder<'a, S> {
pub fn goodreads_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_goodreads_id(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: get_book_state::State> GetBookBuilder<'a, S> {
pub fn id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_id(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S: get_book_state::State> GetBookBuilder<'a, S> {
pub fn isbn(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_isbn(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: get_book_state::State> GetBookBuilder<'a, S> {
pub fn isbn13(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_isbn13(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> GetBookBuilder<'a, S>
where
S: get_book_state::State,
{
pub fn build(self) -> GetBook<'a> {
GetBook {
goodreads_id: self._fields.0,
id: self._fields.1,
isbn: self._fields.2,
isbn13: self._fields.3,
}
}
}