#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::ident::AtIdentifier;
use jacquard_common::types::string::Did;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
use crate::app_bsky::graph::NotFoundActor;
use crate::app_bsky::graph::Relationship;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetRelationships<'a> {
#[serde(borrow)]
pub actor: AtIdentifier<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub others: Option<Vec<AtIdentifier<'a>>>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetRelationshipsOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub actor: Option<Did<'a>>,
#[serde(borrow)]
pub relationships: Vec<GetRelationshipsOutputRelationshipsItem<'a>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
pub enum GetRelationshipsOutputRelationshipsItem<'a> {
#[serde(rename = "app.bsky.graph.defs#relationship")]
Relationship(Box<Relationship<'a>>),
#[serde(rename = "app.bsky.graph.defs#notFoundActor")]
NotFoundActor(Box<NotFoundActor<'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 GetRelationshipsError<'a> {
#[serde(rename = "ActorNotFound")]
ActorNotFound(Option<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),
}
}
}
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;
}
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;
}
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 {}
}
pub trait State: sealed::Sealed {
type Actor;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Actor = Unset;
}
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>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct actor(());
}
}
pub struct GetRelationshipsBuilder<'a, S: get_relationships_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<AtIdentifier<'a>>, Option<Vec<AtIdentifier<'a>>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> GetRelationships<'a> {
pub fn new() -> GetRelationshipsBuilder<'a, get_relationships_state::Empty> {
GetRelationshipsBuilder::new()
}
}
impl<'a> GetRelationshipsBuilder<'a, get_relationships_state::Empty> {
pub fn new() -> Self {
GetRelationshipsBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> GetRelationshipsBuilder<'a, S>
where
S: get_relationships_state::State,
S::Actor: get_relationships_state::IsUnset,
{
pub fn actor(
mut self,
value: impl Into<AtIdentifier<'a>>,
) -> GetRelationshipsBuilder<'a, get_relationships_state::SetActor<S>> {
self._fields.0 = Option::Some(value.into());
GetRelationshipsBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: get_relationships_state::State> GetRelationshipsBuilder<'a, S> {
pub fn others(mut self, value: impl Into<Option<Vec<AtIdentifier<'a>>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_others(mut self, value: Option<Vec<AtIdentifier<'a>>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> GetRelationshipsBuilder<'a, S>
where
S: get_relationships_state::State,
S::Actor: get_relationships_state::IsSet,
{
pub fn build(self) -> GetRelationships<'a> {
GetRelationships {
actor: self._fields.0.unwrap(),
others: self._fields.1,
}
}
}