jacquard-api 0.10.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.graph.getRelationships
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct GetRelationships<'a> {
    #[serde(borrow)]
    pub actor: jacquard_common::types::ident::AtIdentifier<'a>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub others: std::option::Option<
        Vec<jacquard_common::types::ident::AtIdentifier<'a>>,
    >,
}

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

/// Builder for constructing an instance of this type
pub struct GetRelationshipsBuilder<'a, S: get_relationships_state::State> {
    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
    __unsafe_private_named: (
        ::core::option::Option<jacquard_common::types::ident::AtIdentifier<'a>>,
        ::core::option::Option<Vec<jacquard_common::types::ident::AtIdentifier<'a>>>,
    ),
    _phantom: ::core::marker::PhantomData<&'a ()>,
}

impl<'a> GetRelationships<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetRelationshipsBuilder<'a, get_relationships_state::Empty> {
        GetRelationshipsBuilder::new()
    }
}

impl<'a> GetRelationshipsBuilder<'a, get_relationships_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        GetRelationshipsBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: (None, None),
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S> GetRelationshipsBuilder<'a, S>
where
    S: get_relationships_state::State,
    S::Actor: get_relationships_state::IsUnset,
{
    /// Set the `actor` field (required)
    pub fn actor(
        mut self,
        value: impl Into<jacquard_common::types::ident::AtIdentifier<'a>>,
    ) -> GetRelationshipsBuilder<'a, get_relationships_state::SetActor<S>> {
        self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
        GetRelationshipsBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: self.__unsafe_private_named,
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S: get_relationships_state::State> GetRelationshipsBuilder<'a, S> {
    /// Set the `others` field (optional)
    pub fn others(
        mut self,
        value: impl Into<Option<Vec<jacquard_common::types::ident::AtIdentifier<'a>>>>,
    ) -> Self {
        self.__unsafe_private_named.1 = value.into();
        self
    }
    /// Set the `others` field to an Option value (optional)
    pub fn maybe_others(
        mut self,
        value: Option<Vec<jacquard_common::types::ident::AtIdentifier<'a>>>,
    ) -> Self {
        self.__unsafe_private_named.1 = value;
        self
    }
}

impl<'a, S> GetRelationshipsBuilder<'a, S>
where
    S: get_relationships_state::State,
    S::Actor: get_relationships_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetRelationships<'a> {
        GetRelationships {
            actor: self.__unsafe_private_named.0.unwrap(),
            others: self.__unsafe_private_named.1,
        }
    }
}

#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct GetRelationshipsOutput<'a> {
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub actor: std::option::Option<jacquard_common::types::string::Did<'a>>,
    #[serde(borrow)]
    pub relationships: Vec<GetRelationshipsOutputRelationshipsItem<'a>>,
}

#[jacquard_derive::open_union]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum GetRelationshipsOutputRelationshipsItem<'a> {
    #[serde(rename = "app.bsky.graph.defs#relationship")]
    Relationship(Box<crate::app_bsky::graph::Relationship<'a>>),
    #[serde(rename = "app.bsky.graph.defs#notFoundActor")]
    NotFoundActor(Box<crate::app_bsky::graph::NotFoundActor<'a>>),
}

#[jacquard_derive::open_union]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic,
    jacquard_derive::IntoStatic
)]
#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum GetRelationshipsError<'a> {
    /// the primary actor at-identifier could not be resolved
    #[serde(rename = "ActorNotFound")]
    ActorNotFound(std::option::Option<jacquard_common::CowStr<'a>>),
}

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

/// Response type for
///app.bsky.graph.getRelationships
pub struct GetRelationshipsResponse;
impl jacquard_common::xrpc::XrpcResp for GetRelationshipsResponse {
    const NSID: &'static str = "app.bsky.graph.getRelationships";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetRelationshipsOutput<'de>;
    type Err<'de> = GetRelationshipsError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetRelationships<'a> {
    const NSID: &'static str = "app.bsky.graph.getRelationships";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetRelationshipsResponse;
}

/// Endpoint type for
///app.bsky.graph.getRelationships
pub struct GetRelationshipsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetRelationshipsRequest {
    const PATH: &'static str = "/xrpc/app.bsky.graph.getRelationships";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetRelationships<'de>;
    type Response = GetRelationshipsResponse;
}