jacquard-api 0.12.0-beta.1

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: science.alt.dataset.resolveLabel
//
// 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::string::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::science_alt::dataset::label::Label;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ResolveLabel<S: BosStr = DefaultStr> {
    pub handle: S,
    pub name: S,
    ///(max length: 50)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ResolveLabelOutput<S: BosStr = DefaultStr> {
    ///CID of the resolved dataset entry
    pub cid: S,
    ///The label record that was resolved
    pub label: Label<S>,
    ///AT-URI of the resolved dataset entry
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


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

#[serde(tag = "error", content = "message")]
pub enum ResolveLabelError {
    /// No label found with the given name
    #[serde(rename = "LabelNotFound")]
    LabelNotFound(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

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

/// Response type for science.alt.dataset.resolveLabel
pub struct ResolveLabelResponse;
impl jacquard_common::xrpc::XrpcResp for ResolveLabelResponse {
    const NSID: &'static str = "science.alt.dataset.resolveLabel";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ResolveLabelOutput<S>;
    type Err = ResolveLabelError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ResolveLabel<S> {
    const NSID: &'static str = "science.alt.dataset.resolveLabel";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ResolveLabelResponse;
}

/// Endpoint type for science.alt.dataset.resolveLabel
pub struct ResolveLabelRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ResolveLabelRequest {
    const PATH: &'static str = "/xrpc/science.alt.dataset.resolveLabel";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = ResolveLabel<S>;
    type Response = ResolveLabelResponse;
}

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

/// Builder for constructing an instance of this type.
pub struct ResolveLabelBuilder<S: BosStr, St: resolve_label_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<S>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

impl<S: BosStr> ResolveLabel<S> {
    /// Create a new builder for this type.
    pub fn new() -> ResolveLabelBuilder<S, resolve_label_state::Empty> {
        ResolveLabelBuilder::new()
    }
}

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

impl<S: BosStr, St> ResolveLabelBuilder<S, St>
where
    St: resolve_label_state::State,
    St::Handle: resolve_label_state::IsUnset,
{
    /// Set the `handle` field (required)
    pub fn handle(
        mut self,
        value: impl Into<S>,
    ) -> ResolveLabelBuilder<S, resolve_label_state::SetHandle<St>> {
        self._fields.0 = Option::Some(value.into());
        ResolveLabelBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> ResolveLabelBuilder<S, St>
where
    St: resolve_label_state::State,
    St::Name: resolve_label_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<S>,
    ) -> ResolveLabelBuilder<S, resolve_label_state::SetName<St>> {
        self._fields.1 = Option::Some(value.into());
        ResolveLabelBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St: resolve_label_state::State> ResolveLabelBuilder<S, St> {
    /// Set the `version` field (optional)
    pub fn version(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `version` field to an Option value (optional)
    pub fn maybe_version(mut self, value: Option<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<S: BosStr, St> ResolveLabelBuilder<S, St>
where
    St: resolve_label_state::State,
    St::Name: resolve_label_state::IsSet,
    St::Handle: resolve_label_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ResolveLabel<S> {
        ResolveLabel {
            handle: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            version: self._fields.2,
        }
    }
}