// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.graph.getTaggedResources
//
// 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::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::sh_weaver::graph::TagView;
use crate::sh_weaver::notebook::EntryView;
use crate::sh_weaver::notebook::NotebookView;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetTaggedResources<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    ///  Defaults to `true`.
    #[serde(default = "_default_include_author_tags")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_author_tags: Option<bool>,
    ///  Defaults to `true`.
    #[serde(default = "_default_include_community_tags")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_community_tags: Option<bool>,
    /// Defaults to `50`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Defaults to `"all"`.
    #[serde(default = "_default_resource_type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub resource_type: Option<S>,
    /// Defaults to `"recent"`.
    #[serde(default = "_default_sort")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort: Option<S>,
    pub tag: S,
}


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


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum GetTaggedResourcesOutputResourcesItem<S: BosStr = DefaultStr> {
    #[serde(rename = "sh.weaver.notebook.defs#notebookView")]
    NotebookView(Box<NotebookView<S>>),
    #[serde(rename = "sh.weaver.notebook.defs#entryView")]
    EntryView(Box<EntryView<S>>),
}

/** Response marker for the `sh.weaver.graph.getTaggedResources` query.

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

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetTaggedResources<S> {
    const NSID: &'static str = "sh.weaver.graph.getTaggedResources";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetTaggedResourcesResponse;
}

/** Endpoint marker for the `sh.weaver.graph.getTaggedResources` query.

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

fn _default_include_author_tags() -> Option<bool> {
    Some(true)
}

fn _default_include_community_tags() -> Option<bool> {
    Some(true)
}

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

fn _default_resource_type<S: jacquard_common::FromStaticStr>() -> Option<S> {
    Some(S::from_static("all"))
}

fn _default_sort<S: jacquard_common::FromStaticStr>() -> Option<S> {
    Some(S::from_static("recent"))
}

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

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

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

impl<S: BosStr> GetTaggedResources<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetTaggedResourcesBuilder<get_tagged_resources_state::Empty, S> {
        GetTaggedResourcesBuilder::builder()
    }
}

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

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

impl<St: get_tagged_resources_state::State, S: BosStr> GetTaggedResourcesBuilder<St, S> {
    /// Set the `cursor` field (optional)
    pub fn cursor(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `cursor` field to an Option value (optional)
    pub fn maybe_cursor(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: get_tagged_resources_state::State, S: BosStr> GetTaggedResourcesBuilder<St, S> {
    /// Set the `includeAuthorTags` field (optional)
    pub fn include_author_tags(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `includeAuthorTags` field to an Option value (optional)
    pub fn maybe_include_author_tags(mut self, value: Option<bool>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: get_tagged_resources_state::State, S: BosStr> GetTaggedResourcesBuilder<St, S> {
    /// Set the `includeCommunityTags` field (optional)
    pub fn include_community_tags(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `includeCommunityTags` field to an Option value (optional)
    pub fn maybe_include_community_tags(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<St: get_tagged_resources_state::State, S: BosStr> GetTaggedResourcesBuilder<St, S> {
    /// Set the `resourceType` field (optional)
    pub fn resource_type(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `resourceType` field to an Option value (optional)
    pub fn maybe_resource_type(mut self, value: Option<S>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: get_tagged_resources_state::State, S: BosStr> GetTaggedResourcesBuilder<St, S> {
    /// Set the `sort` field (optional)
    pub fn sort(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `sort` field to an Option value (optional)
    pub fn maybe_sort(mut self, value: Option<S>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St, S: BosStr> GetTaggedResourcesBuilder<St, S>
where
    St: get_tagged_resources_state::State,
    St::Tag: get_tagged_resources_state::IsUnset,
{
    /// Set the `tag` field (required)
    pub fn tag(
        mut self,
        value: impl Into<S>,
    ) -> GetTaggedResourcesBuilder<get_tagged_resources_state::SetTag<St>, S> {
        self._fields.6 = Option::Some(value.into());
        GetTaggedResourcesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetTaggedResourcesBuilder<St, S>
where
    St: get_tagged_resources_state::State,
    St::Tag: get_tagged_resources_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetTaggedResources<S> {
        GetTaggedResources {
            cursor: self._fields.0,
            include_author_tags: self._fields.1,
            include_community_tags: self._fields.2,
            limit: self._fields.3,
            resource_type: self._fields.4,
            sort: self._fields.5,
            tag: self._fields.6.unwrap(),
        }
    }
}