// @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;
use jacquard_derive::{IntoStatic, lexicon, 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")]
pub struct GetTaggedResources<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    /// 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")]
    #[serde(borrow)]
    pub resource_type: Option<CowStr<'a>>,
    ///Defaults to `"recent"`.
    #[serde(default = "_default_sort")]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub sort: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub tag: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetTaggedResourcesOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub resources: Vec<GetTaggedResourcesOutputResourcesItem<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tag: Option<TagView<'a>>,
}


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

/// Response type for sh.weaver.graph.getTaggedResources
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<'de> = GetTaggedResourcesOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Endpoint type for sh.weaver.graph.getTaggedResources
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<'de> = GetTaggedResources<'de>;
    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() -> Option<CowStr<'static>> {
    Some(CowStr::from("all"))
}

fn _default_sort() -> Option<CowStr<'static>> {
    Some(CowStr::from("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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTag<S> {}
    impl<S: State> State for SetTag<S> {
        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<'a, S: get_tagged_resources_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<bool>,
        Option<bool>,
        Option<i64>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: get_tagged_resources_state::State> GetTaggedResourcesBuilder<'a, 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<'a, S: get_tagged_resources_state::State> GetTaggedResourcesBuilder<'a, 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<'a, S: get_tagged_resources_state::State> GetTaggedResourcesBuilder<'a, 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<'a, S: get_tagged_resources_state::State> GetTaggedResourcesBuilder<'a, S> {
    /// Set the `resourceType` field (optional)
    pub fn resource_type(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

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

impl<'a, S> GetTaggedResourcesBuilder<'a, S>
where
    S: get_tagged_resources_state::State,
    S::Tag: get_tagged_resources_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetTaggedResources<'a> {
        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(),
        }
    }
}