jacquard-api 0.11.1

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.notebook.getEntryDetail
//
// 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_common::types::string::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
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 GetEntryDetail<'a> {
    #[serde(borrow)]
    pub entry: AtUri<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub notebook_context: Option<AtUri<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetEntryDetailOutput<'a> {
    #[serde(borrow)]
    pub entry: EntryView<'a>,
    pub notebook_count: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub notebooks: Option<Vec<NotebookView<'a>>>,
    #[serde(borrow)]
    pub record: Data<'a>,
}


#[open_union]
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic,
    IntoStatic
)]

#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum GetEntryDetailError<'a> {
    #[serde(rename = "EntryNotFound")]
    EntryNotFound(Option<CowStr<'a>>),
}

impl core::fmt::Display for GetEntryDetailError<'_> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::EntryNotFound(msg) => {
                write!(f, "EntryNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

/// Response type for sh.weaver.notebook.getEntryDetail
pub struct GetEntryDetailResponse;
impl jacquard_common::xrpc::XrpcResp for GetEntryDetailResponse {
    const NSID: &'static str = "sh.weaver.notebook.getEntryDetail";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetEntryDetailOutput<'de>;
    type Err<'de> = GetEntryDetailError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetEntryDetail<'a> {
    const NSID: &'static str = "sh.weaver.notebook.getEntryDetail";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetEntryDetailResponse;
}

/// Endpoint type for sh.weaver.notebook.getEntryDetail
pub struct GetEntryDetailRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetEntryDetailRequest {
    const PATH: &'static str = "/xrpc/sh.weaver.notebook.getEntryDetail";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetEntryDetail<'de>;
    type Response = GetEntryDetailResponse;
}

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

/// Builder for constructing an instance of this type
pub struct GetEntryDetailBuilder<'a, S: get_entry_detail_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<AtUri<'a>>, Option<AtUri<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> GetEntryDetail<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetEntryDetailBuilder<'a, get_entry_detail_state::Empty> {
        GetEntryDetailBuilder::new()
    }
}

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

impl<'a, S> GetEntryDetailBuilder<'a, S>
where
    S: get_entry_detail_state::State,
    S::Entry: get_entry_detail_state::IsUnset,
{
    /// Set the `entry` field (required)
    pub fn entry(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> GetEntryDetailBuilder<'a, get_entry_detail_state::SetEntry<S>> {
        self._fields.0 = Option::Some(value.into());
        GetEntryDetailBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: get_entry_detail_state::State> GetEntryDetailBuilder<'a, S> {
    /// Set the `notebookContext` field (optional)
    pub fn notebook_context(mut self, value: impl Into<Option<AtUri<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `notebookContext` field to an Option value (optional)
    pub fn maybe_notebook_context(mut self, value: Option<AtUri<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> GetEntryDetailBuilder<'a, S>
where
    S: get_entry_detail_state::State,
    S::Entry: get_entry_detail_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetEntryDetail<'a> {
        GetEntryDetail {
            entry: self._fields.0.unwrap(),
            notebook_context: self._fields.1,
        }
    }
}