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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_derive::{IntoStatic, lexicon};
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>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetSuggestedNotebooksOutput<'a> {
    #[serde(borrow)]
    pub notebooks: Vec<get_suggested_notebooks::SuggestedNotebook<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SuggestedNotebook<'a> {
    #[serde(borrow)]
    pub notebook: NotebookView<'a>,
    #[serde(borrow)]
    pub reason: get_suggested_notebooks::SuggestionReason<'a>,
    ///Appview-computed relevance score.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub score: Option<i64>,
}

/// Why this notebook was suggested.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct SuggestionReason<'a> {
    ///If followed-author, the author.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub related_author: Option<ProfileViewBasic<'a>>,
    ///If from-list, the list it's from.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub related_list: Option<ListView<'a>>,
    ///If similar-to-X, the notebook it's similar to.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub related_notebook: Option<NotebookView<'a>>,
    ///Tags that matched.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub related_tags: Option<Vec<CowStr<'a>>>,
    #[serde(borrow)]
    pub r#type: SuggestionReasonType<'a>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SuggestionReasonType<'a> {
    SimilarTags,
    SimilarToLiked,
    SimilarToRead,
    FollowedAuthor,
    PopularInTag,
    Trending,
    FromList,
    Other(CowStr<'a>),
}

impl<'a> SuggestionReasonType<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for SuggestionReasonType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "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(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for SuggestionReasonType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "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(CowStr::from(s)),
        }
    }
}

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

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

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

impl jacquard_common::IntoStatic for SuggestionReasonType<'_> {
    type Output = SuggestionReasonType<'static>;
    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 type for sh.weaver.notebook.getSuggestedNotebooks
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<'de> = GetSuggestedNotebooksOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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 type for sh.weaver.notebook.getSuggestedNotebooks
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<'de> = GetSuggestedNotebooks;
    type Response = GetSuggestedNotebooksResponse;
}

impl<'a> LexiconSchema for SuggestedNotebook<'a> {
    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<'a> LexiconSchema for SuggestionReason<'a> {
    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<S: get_suggested_notebooks_state::State> {
    _state: PhantomData<fn() -> S>,
    _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
    pub fn new() -> Self {
        GetSuggestedNotebooksBuilder {
            _state: PhantomData,
            _fields: (None,),
        }
    }
}

impl<S: get_suggested_notebooks_state::State> GetSuggestedNotebooksBuilder<S> {
    /// 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<S> GetSuggestedNotebooksBuilder<S>
where
    S: 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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetNotebook<S> {}
    impl<S: State> State for SetNotebook<S> {
        type Notebook = Set<members::notebook>;
        type Reason = S::Reason;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetReason<S> {}
    impl<S: State> State for SetReason<S> {
        type Notebook = S::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<'a, S: suggested_notebook_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<NotebookView<'a>>,
        Option<get_suggested_notebooks::SuggestionReason<'a>>,
        Option<i64>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S: suggested_notebook_state::State> SuggestedNotebookBuilder<'a, 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<'a, S> SuggestedNotebookBuilder<'a, S>
where
    S: suggested_notebook_state::State,
    S::Notebook: suggested_notebook_state::IsSet,
    S::Reason: suggested_notebook_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> SuggestedNotebook<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> SuggestedNotebook<'a> {
        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()
    }
}