// @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, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::string::Datetime;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetBook<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub goodreads_id: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub isbn: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub isbn13: Option<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetBookOutput<S: BosStr = DefaultStr> {
    ///Other users' activity on the book
    #[serde(skip_serializing_if = "Option::is_none")]
    pub activity: Option<Vec<Activity<S>>>,
    ///The hive book's info
    pub book: HiveBook<S>,
    ///Reading progress for the user
    #[serde(skip_serializing_if = "Option::is_none")]
    pub book_progress: Option<BookProgress<S>>,
    ///Comments on the book
    pub comments: Vec<Comment<S>>,
    ///Cover image of the book
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cover: Option<BlobRef<S>>,
    #[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")]
    pub review: Option<S>,
    ///Reviews of the book
    pub reviews: Vec<Review<S>>,
    ///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")]
    pub status: Option<GetBookOutputStatus<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 GetBookOutputStatus<S: BosStr = DefaultStr> {
    Finished,
    Reading,
    WantToRead,
    Abandoned,
    Owned,
    Other(S),
}

impl<S: BosStr> GetBookOutputStatus<S> {
    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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "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(s),
        }
    }
}

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

impl<S: BosStr> AsRef<str> for GetBookOutputStatus<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<S: BosStr> jacquard_common::IntoStatic for GetBookOutputStatus<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = GetBookOutputStatus<S::Output>;
    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 marker for the `buzz.bookhive.getBook` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetBookOutput<S>` for this endpoint.*/
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<S: BosStr> = GetBookOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

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

/** Endpoint marker for the `buzz.bookhive.getBook` query.

Path: `/xrpc/buzz.bookhive.getBook`. The request payload type is `GetBook<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
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<S: BosStr> = GetBook<S>;
    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<St: get_book_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<S>, Option<S>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

impl GetBook<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> GetBookBuilder<get_book_state::Empty, DefaultStr> {
        GetBookBuilder::new()
    }
}

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

impl GetBookBuilder<get_book_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        GetBookBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> GetBookBuilder<get_book_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        GetBookBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St: get_book_state::State, S: BosStr> GetBookBuilder<St, S> {
    /// Set the `goodreadsId` field (optional)
    pub fn goodreads_id(mut self, value: impl Into<Option<S>>) -> 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<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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

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