// @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.

#[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> {
    ///Other users' activity on the book
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub activity: Option<Vec<Activity<'a>>>,
    ///The hive book's info
    #[serde(borrow)]
    pub book: HiveBook<'a>,
    ///Reading progress for the user
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub book_progress: Option<BookProgress<'a>>,
    ///Comments on the book
    #[serde(borrow)]
    pub comments: Vec<Comment<'a>>,
    ///Cover image of the book
    #[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>,
    ///The date the user finished reading the book
    #[serde(skip_serializing_if = "Option::is_none")]
    pub finished_at: Option<Datetime>,
    ///The book's review
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub review: Option<CowStr<'a>>,
    ///Reviews of the book
    #[serde(borrow)]
    pub reviews: Vec<Review<'a>>,
    ///Number of stars given to the book (1-10) which will be mapped to 1-5 stars
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stars: Option<i64>,
    ///The date the user started reading the book
    #[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()),
        }
    }
}

/// 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;
}

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> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: 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 {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _lifetime: 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<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `goodreadsId` field to an Option value (optional)
    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> {
    /// Set the `id` field (optional)
    pub fn id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `id` field to an Option value (optional)
    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> {
    /// Set the `isbn` field (optional)
    pub fn isbn(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `isbn` field to an Option value (optional)
    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> {
    /// Set the `isbn13` field (optional)
    pub fn isbn13(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `isbn13` field to an Option value (optional)
    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,
{
    /// Build the final struct
    pub fn build(self) -> GetBook<'a> {
        GetBook {
            goodreads_id: self._fields.0,
            id: self._fields.1,
            isbn: self._fields.2,
            isbn13: self._fields.3,
        }
    }
}