#[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 {
#[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>,
#[serde(skip_serializing_if = "Option::is_none")]
pub score: Option<i64>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct SuggestionReason<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub related_author: Option<ProfileViewBasic<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub related_list: Option<ListView<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub related_notebook: Option<NotebookView<'a>>,
#[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())
}
}
}
}
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;
}
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 {}
}
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 GetSuggestedNotebooksBuilder<S: get_suggested_notebooks_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<i64>,),
}
impl GetSuggestedNotebooks {
pub fn new() -> GetSuggestedNotebooksBuilder<get_suggested_notebooks_state::Empty> {
GetSuggestedNotebooksBuilder::new()
}
}
impl GetSuggestedNotebooksBuilder<get_suggested_notebooks_state::Empty> {
pub fn new() -> Self {
GetSuggestedNotebooksBuilder {
_state: PhantomData,
_fields: (None,),
}
}
}
impl<S: get_suggested_notebooks_state::State> GetSuggestedNotebooksBuilder<S> {
pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.0 = value.into();
self
}
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,
{
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 {}
}
pub trait State: sealed::Sealed {
type Reason;
type Notebook;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Reason = Unset;
type Notebook = Unset;
}
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 Reason = Set<members::reason>;
type Notebook = S::Notebook;
}
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 Reason = S::Reason;
type Notebook = Set<members::notebook>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct reason(());
pub struct notebook(());
}
}
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> {
pub fn new() -> SuggestedNotebookBuilder<'a, suggested_notebook_state::Empty> {
SuggestedNotebookBuilder::new()
}
}
impl<'a> SuggestedNotebookBuilder<'a, suggested_notebook_state::Empty> {
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,
{
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,
{
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> {
pub fn score(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.2 = value.into();
self
}
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::Reason: suggested_notebook_state::IsSet,
S::Notebook: suggested_notebook_state::IsSet,
{
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(),
}
}
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()
}
}