jacquard-api 0.12.0-beta.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atprotofans.validateSupporter
//
// 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;

use crate::com_atprotofans::hydrated_profile::HydratedProfile;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::Did;
use jacquard_common::types::value::Data;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::{IntoStatic, open_union};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ValidateSupporter<S: BosStr = DefaultStr> {
    pub signer: Did<S>,
    pub subject: Did<S>,
    pub supporter: Did<S>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ValidateSupporterOutput<S: BosStr = DefaultStr> {
    ///Hydrated profile of the supporter, if available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub profile: Option<HydratedProfile<S>>,
    ///Whether the supporter relationship exists and the required attestation is valid.
    pub valid: bool,
    #[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 ValidateSupporterError {
    /// Invalid DID format or missing required parameters.
    #[serde(rename = "InvalidRequest")]
    InvalidRequest(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other {
        error: SmolStr,
        message: Option<SmolStr>,
    },
}

impl core::fmt::Display for ValidateSupporterError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::InvalidRequest(msg) => {
                write!(f, "InvalidRequest")?;
                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 com.atprotofans.validateSupporter
pub struct ValidateSupporterResponse;
impl jacquard_common::xrpc::XrpcResp for ValidateSupporterResponse {
    const NSID: &'static str = "com.atprotofans.validateSupporter";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ValidateSupporterOutput<S>;
    type Err = ValidateSupporterError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ValidateSupporter<S> {
    const NSID: &'static str = "com.atprotofans.validateSupporter";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ValidateSupporterResponse;
}

/// Endpoint type for com.atprotofans.validateSupporter
pub struct ValidateSupporterRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ValidateSupporterRequest {
    const PATH: &'static str = "/xrpc/com.atprotofans.validateSupporter";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = ValidateSupporter<S>;
    type Response = ValidateSupporterResponse;
}

pub mod validate_supporter_state {

    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
    #[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 Signer;
        type Supporter;
        type Subject;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Signer = Unset;
        type Supporter = Unset;
        type Subject = Unset;
    }
    ///State transition - sets the `signer` field to Set
    pub struct SetSigner<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSigner<St> {}
    impl<St: State> State for SetSigner<St> {
        type Signer = Set<members::signer>;
        type Supporter = St::Supporter;
        type Subject = St::Subject;
    }
    ///State transition - sets the `supporter` field to Set
    pub struct SetSupporter<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSupporter<St> {}
    impl<St: State> State for SetSupporter<St> {
        type Signer = St::Signer;
        type Supporter = Set<members::supporter>;
        type Subject = St::Subject;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSubject<St> {}
    impl<St: State> State for SetSubject<St> {
        type Signer = St::Signer;
        type Supporter = St::Supporter;
        type Subject = Set<members::subject>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `signer` field
        pub struct signer(());
        ///Marker type for the `supporter` field
        pub struct supporter(());
        ///Marker type for the `subject` field
        pub struct subject(());
    }
}

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

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

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

impl<S: BosStr, St> ValidateSupporterBuilder<S, St>
where
    St: validate_supporter_state::State,
    St::Signer: validate_supporter_state::IsUnset,
{
    /// Set the `signer` field (required)
    pub fn signer(
        mut self,
        value: impl Into<Did<S>>,
    ) -> ValidateSupporterBuilder<S, validate_supporter_state::SetSigner<St>> {
        self._fields.0 = Option::Some(value.into());
        ValidateSupporterBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> ValidateSupporterBuilder<S, St>
where
    St: validate_supporter_state::State,
    St::Subject: validate_supporter_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<Did<S>>,
    ) -> ValidateSupporterBuilder<S, validate_supporter_state::SetSubject<St>> {
        self._fields.1 = Option::Some(value.into());
        ValidateSupporterBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> ValidateSupporterBuilder<S, St>
where
    St: validate_supporter_state::State,
    St::Supporter: validate_supporter_state::IsUnset,
{
    /// Set the `supporter` field (required)
    pub fn supporter(
        mut self,
        value: impl Into<Did<S>>,
    ) -> ValidateSupporterBuilder<S, validate_supporter_state::SetSupporter<St>> {
        self._fields.2 = Option::Some(value.into());
        ValidateSupporterBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> ValidateSupporterBuilder<S, St>
where
    St: validate_supporter_state::State,
    St::Signer: validate_supporter_state::IsSet,
    St::Supporter: validate_supporter_state::IsSet,
    St::Subject: validate_supporter_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ValidateSupporter<S> {
        ValidateSupporter {
            signer: self._fields.0.unwrap(),
            subject: self._fields.1.unwrap(),
            supporter: self._fields.2.unwrap(),
        }
    }
}