// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.notebook.getSuggestedNotebooks
//
// 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};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::sh_weaver::actor::ProfileViewBasic;
use crate::sh_weaver::graph::ListView;
use crate::sh_weaver::notebook::NotebookView;
use crate::sh_weaver::notebook::get_suggested_notebooks;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetSuggestedNotebooks {
    /// Defaults to `20`. Min: 1. Max: 50.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetSuggestedNotebooksOutput<S: BosStr = DefaultStr> {
    pub notebooks: Vec<get_suggested_notebooks::SuggestedNotebook<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SuggestedNotebook<S: BosStr = DefaultStr> {
    pub notebook: NotebookView<S>,
    pub reason: get_suggested_notebooks::SuggestionReason<S>,
    ///Appview-computed relevance score.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub score: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Why this notebook was suggested.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SuggestionReason<S: BosStr = DefaultStr> {
    ///If followed-author, the author.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub related_author: Option<ProfileViewBasic<S>>,
    ///If from-list, the list it's from.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub related_list: Option<ListView<S>>,
    ///If similar-to-X, the notebook it's similar to.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub related_notebook: Option<NotebookView<S>>,
    ///Tags that matched.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub related_tags: Option<Vec<S>>,
    pub r#type: SuggestionReasonType<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 SuggestionReasonType<S: BosStr = DefaultStr> {
    SimilarTags,
    SimilarToLiked,
    SimilarToRead,
    FollowedAuthor,
    PopularInTag,
    Trending,
    FromList,
    Other(S),
}

impl<S: BosStr> SuggestionReasonType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::SimilarTags => "similar-tags",
            Self::SimilarToLiked => "similar-to-liked",
            Self::SimilarToRead => "similar-to-read",
            Self::FollowedAuthor => "followed-author",
            Self::PopularInTag => "popular-in-tag",
            Self::Trending => "trending",
            Self::FromList => "from-list",
            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() {
            "similar-tags" => Self::SimilarTags,
            "similar-to-liked" => Self::SimilarToLiked,
            "similar-to-read" => Self::SimilarToRead,
            "followed-author" => Self::FollowedAuthor,
            "popular-in-tag" => Self::PopularInTag,
            "trending" => Self::Trending,
            "from-list" => Self::FromList,
            _ => Self::Other(s),
        }
    }
}

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for SuggestionReasonType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = SuggestionReasonType<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            SuggestionReasonType::SimilarTags => SuggestionReasonType::SimilarTags,
            SuggestionReasonType::SimilarToLiked => SuggestionReasonType::SimilarToLiked,
            SuggestionReasonType::SimilarToRead => SuggestionReasonType::SimilarToRead,
            SuggestionReasonType::FollowedAuthor => SuggestionReasonType::FollowedAuthor,
            SuggestionReasonType::PopularInTag => SuggestionReasonType::PopularInTag,
            SuggestionReasonType::Trending => SuggestionReasonType::Trending,
            SuggestionReasonType::FromList => SuggestionReasonType::FromList,
            SuggestionReasonType::Other(v) => {
                SuggestionReasonType::Other(v.into_static())
            }
        }
    }
}

/** Response marker for the `sh.weaver.notebook.getSuggestedNotebooks` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetSuggestedNotebooksOutput<S>` for this endpoint.*/
pub struct GetSuggestedNotebooksResponse;
impl jacquard_common::xrpc::XrpcResp for GetSuggestedNotebooksResponse {
    const NSID: &'static str = "sh.weaver.notebook.getSuggestedNotebooks";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetSuggestedNotebooksOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl jacquard_common::xrpc::XrpcRequest for GetSuggestedNotebooks {
    const NSID: &'static str = "sh.weaver.notebook.getSuggestedNotebooks";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetSuggestedNotebooksResponse;
}

/** Endpoint marker for the `sh.weaver.notebook.getSuggestedNotebooks` query.

Path: `/xrpc/sh.weaver.notebook.getSuggestedNotebooks`. The request payload type is `GetSuggestedNotebooks`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetSuggestedNotebooksRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetSuggestedNotebooksRequest {
    const PATH: &'static str = "/xrpc/sh.weaver.notebook.getSuggestedNotebooks";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetSuggestedNotebooks;
    type Response = GetSuggestedNotebooksResponse;
}

impl<S: BosStr> LexiconSchema for SuggestedNotebook<S> {
    fn nsid() -> &'static str {
        "sh.weaver.notebook.getSuggestedNotebooks"
    }
    fn def_name() -> &'static str {
        "suggestedNotebook"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notebook_getSuggestedNotebooks()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for SuggestionReason<S> {
    fn nsid() -> &'static str {
        "sh.weaver.notebook.getSuggestedNotebooks"
    }
    fn def_name() -> &'static str {
        "suggestionReason"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notebook_getSuggestedNotebooks()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn _default_limit() -> Option<i64> {
    Some(20i64)
}

pub mod get_suggested_notebooks_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 GetSuggestedNotebooksBuilder<St: get_suggested_notebooks_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<i64>,),
}

impl GetSuggestedNotebooks {
    /// Create a new builder for this type.
    pub fn new() -> GetSuggestedNotebooksBuilder<get_suggested_notebooks_state::Empty> {
        GetSuggestedNotebooksBuilder::new()
    }
}

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

impl GetSuggestedNotebooksBuilder<get_suggested_notebooks_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        GetSuggestedNotebooksBuilder {
            _state: PhantomData,
            _fields: (None,),
        }
    }
}

impl<St: get_suggested_notebooks_state::State> GetSuggestedNotebooksBuilder<St> {
    /// Set the `limit` field (optional)
    pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `limit` field to an Option value (optional)
    pub fn maybe_limit(mut self, value: Option<i64>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St> GetSuggestedNotebooksBuilder<St>
where
    St: get_suggested_notebooks_state::State,
{
    /// Build the final struct.
    pub fn build(self) -> GetSuggestedNotebooks {
        GetSuggestedNotebooks {
            limit: self._fields.0,
        }
    }
}

pub mod suggested_notebook_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;
        type Reason;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Notebook = Unset;
        type Reason = Unset;
    }
    ///State transition - sets the `notebook` field to Set
    pub struct SetNotebook<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetNotebook<St> {}
    impl<St: State> State for SetNotebook<St> {
        type Notebook = Set<members::notebook>;
        type Reason = St::Reason;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReason<St> {}
    impl<St: State> State for SetReason<St> {
        type Notebook = St::Notebook;
        type Reason = Set<members::reason>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `notebook` field
        pub struct notebook(());
        ///Marker type for the `reason` field
        pub struct reason(());
    }
}

/// Builder for constructing an instance of this type.
pub struct SuggestedNotebookBuilder<
    St: suggested_notebook_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<NotebookView<S>>,
        Option<get_suggested_notebooks::SuggestionReason<S>>,
        Option<i64>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> SuggestedNotebook<S> {
    /// Create a new builder for this type
    pub fn builder() -> SuggestedNotebookBuilder<suggested_notebook_state::Empty, S> {
        SuggestedNotebookBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SuggestedNotebookBuilder<St, S>
where
    St: suggested_notebook_state::State,
    St::Notebook: suggested_notebook_state::IsUnset,
{
    /// Set the `notebook` field (required)
    pub fn notebook(
        mut self,
        value: impl Into<NotebookView<S>>,
    ) -> SuggestedNotebookBuilder<suggested_notebook_state::SetNotebook<St>, S> {
        self._fields.0 = Option::Some(value.into());
        SuggestedNotebookBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SuggestedNotebookBuilder<St, S>
where
    St: suggested_notebook_state::State,
    St::Reason: suggested_notebook_state::IsUnset,
{
    /// Set the `reason` field (required)
    pub fn reason(
        mut self,
        value: impl Into<get_suggested_notebooks::SuggestionReason<S>>,
    ) -> SuggestedNotebookBuilder<suggested_notebook_state::SetReason<St>, S> {
        self._fields.1 = Option::Some(value.into());
        SuggestedNotebookBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> SuggestedNotebookBuilder<St, S>
where
    St: suggested_notebook_state::State,
    St::Notebook: suggested_notebook_state::IsSet,
    St::Reason: suggested_notebook_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> SuggestedNotebook<S> {
        SuggestedNotebook {
            notebook: self._fields.0.unwrap(),
            reason: self._fields.1.unwrap(),
            score: self._fields.2,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> SuggestedNotebook<S> {
        SuggestedNotebook {
            notebook: self._fields.0.unwrap(),
            reason: self._fields.1.unwrap(),
            score: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_notebook_getSuggestedNotebooks() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("sh.weaver.notebook.getSuggestedNotebooks"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("suggestedNotebook"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("notebook"),
                            SmolStr::new_static("reason")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("notebook"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "sh.weaver.notebook.defs#notebookView",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("reason"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#suggestionReason"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("score"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("suggestionReason"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Why this notebook was suggested."),
                    ),
                    required: Some(vec![SmolStr::new_static("type")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("relatedAuthor"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "sh.weaver.actor.defs#profileViewBasic",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("relatedList"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("sh.weaver.graph.defs#listView"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("relatedNotebook"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "sh.weaver.notebook.defs#notebookView",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("relatedTags"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(CowStr::new_static("Tags that matched.")),
                                items: LexArrayItem::String(LexString {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}