#[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_derive::{IntoStatic, lexicon, 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")]
pub struct ResolveLabel<'a> {
#[serde(borrow)]
pub handle: CowStr<'a>,
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub version: Option<CowStr<'a>>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ResolveLabelOutput<'a> {
#[serde(borrow)]
pub cid: CowStr<'a>,
#[serde(borrow)]
pub label: Label<'a>,
#[serde(borrow)]
pub uri: AtUri<'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 ResolveLabelError<'a> {
#[serde(rename = "LabelNotFound")]
LabelNotFound(Option<CowStr<'a>>),
}
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::Unknown(err) => write!(f, "Unknown error: {:?}", err),
}
}
}
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<'de> = ResolveLabelOutput<'de>;
type Err<'de> = ResolveLabelError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for ResolveLabel<'a> {
const NSID: &'static str = "science.alt.dataset.resolveLabel";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
type Response = ResolveLabelResponse;
}
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<'de> = ResolveLabel<'de>;
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 {}
}
pub trait State: sealed::Sealed {
type Handle;
type Name;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Handle = Unset;
type Name = Unset;
}
pub struct SetHandle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetHandle<S> {}
impl<S: State> State for SetHandle<S> {
type Handle = Set<members::handle>;
type Name = S::Name;
}
pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetName<S> {}
impl<S: State> State for SetName<S> {
type Handle = S::Handle;
type Name = Set<members::name>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct handle(());
pub struct name(());
}
}
pub struct ResolveLabelBuilder<'a, S: resolve_label_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> ResolveLabel<'a> {
pub fn new() -> ResolveLabelBuilder<'a, resolve_label_state::Empty> {
ResolveLabelBuilder::new()
}
}
impl<'a> ResolveLabelBuilder<'a, resolve_label_state::Empty> {
pub fn new() -> Self {
ResolveLabelBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ResolveLabelBuilder<'a, S>
where
S: resolve_label_state::State,
S::Handle: resolve_label_state::IsUnset,
{
pub fn handle(
mut self,
value: impl Into<CowStr<'a>>,
) -> ResolveLabelBuilder<'a, resolve_label_state::SetHandle<S>> {
self._fields.0 = Option::Some(value.into());
ResolveLabelBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ResolveLabelBuilder<'a, S>
where
S: resolve_label_state::State,
S::Name: resolve_label_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<CowStr<'a>>,
) -> ResolveLabelBuilder<'a, resolve_label_state::SetName<S>> {
self._fields.1 = Option::Some(value.into());
ResolveLabelBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: resolve_label_state::State> ResolveLabelBuilder<'a, S> {
pub fn version(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_version(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> ResolveLabelBuilder<'a, S>
where
S: resolve_label_state::State,
S::Handle: resolve_label_state::IsSet,
S::Name: resolve_label_state::IsSet,
{
pub fn build(self) -> ResolveLabel<'a> {
ResolveLabel {
handle: self._fields.0.unwrap(),
name: self._fields.1.unwrap(),
version: self._fields.2,
}
}
}