#[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,
#[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> {
pub cid: S,
pub label: Label<S>,
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 {
#[serde(rename = "LabelNotFound")]
LabelNotFound(Option<SmolStr>),
#[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(())
}
}
}
}
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;
}
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 {}
}
pub trait State: sealed::Sealed {
type Name;
type Handle;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Name = Unset;
type Handle = Unset;
}
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;
}
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>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct name(());
pub struct handle(());
}
}
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> {
pub fn new() -> ResolveLabelBuilder<S, resolve_label_state::Empty> {
ResolveLabelBuilder::new()
}
}
impl<S: BosStr> ResolveLabelBuilder<S, resolve_label_state::Empty> {
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,
{
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,
{
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> {
pub fn version(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
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,
{
pub fn build(self) -> ResolveLabel<S> {
ResolveLabel {
handle: self._fields.0.unwrap(),
name: self._fields.1.unwrap(),
version: self._fields.2,
}
}
}