jacquard-api 0.10.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.sync.getRepoStatus
//
// 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 GetRepoStatus<'a> {
    #[serde(borrow)]
    pub did: jacquard_common::types::string::Did<'a>,
}

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

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

impl<'a> GetRepoStatus<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetRepoStatusBuilder<'a, get_repo_status_state::Empty> {
        GetRepoStatusBuilder::new()
    }
}

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

impl<'a, S> GetRepoStatusBuilder<'a, S>
where
    S: get_repo_status_state::State,
    S::Did: get_repo_status_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<jacquard_common::types::string::Did<'a>>,
    ) -> GetRepoStatusBuilder<'a, get_repo_status_state::SetDid<S>> {
        self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
        GetRepoStatusBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: self.__unsafe_private_named,
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S> GetRepoStatusBuilder<'a, S>
where
    S: get_repo_status_state::State,
    S::Did: get_repo_status_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetRepoStatus<'a> {
        GetRepoStatus {
            did: self.__unsafe_private_named.0.unwrap(),
        }
    }
}

#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct GetRepoStatusOutput<'a> {
    pub active: bool,
    #[serde(borrow)]
    pub did: jacquard_common::types::string::Did<'a>,
    ///Optional field, the current rev of the repo, if active=true
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub rev: std::option::Option<jacquard_common::types::string::Tid>,
    ///If active=false, this optional field indicates a possible reason for why the account is not active. If active=false and no status is supplied, then the host makes no claim for why the repository is no longer being hosted.
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub status: std::option::Option<GetRepoStatusOutputStatus<'a>>,
}

/// If active=false, this optional field indicates a possible reason for why the account is not active. If active=false and no status is supplied, then the host makes no claim for why the repository is no longer being hosted.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GetRepoStatusOutputStatus<'a> {
    Takendown,
    Suspended,
    Deleted,
    Deactivated,
    Desynchronized,
    Throttled,
    Other(jacquard_common::CowStr<'a>),
}

impl<'a> GetRepoStatusOutputStatus<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Takendown => "takendown",
            Self::Suspended => "suspended",
            Self::Deleted => "deleted",
            Self::Deactivated => "deactivated",
            Self::Desynchronized => "desynchronized",
            Self::Throttled => "throttled",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for GetRepoStatusOutputStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "takendown" => Self::Takendown,
            "suspended" => Self::Suspended,
            "deleted" => Self::Deleted,
            "deactivated" => Self::Deactivated,
            "desynchronized" => Self::Desynchronized,
            "throttled" => Self::Throttled,
            _ => Self::Other(jacquard_common::CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for GetRepoStatusOutputStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "takendown" => Self::Takendown,
            "suspended" => Self::Suspended,
            "deleted" => Self::Deleted,
            "deactivated" => Self::Deactivated,
            "desynchronized" => Self::Desynchronized,
            "throttled" => Self::Throttled,
            _ => Self::Other(jacquard_common::CowStr::from(s)),
        }
    }
}

impl<'a> core::fmt::Display for GetRepoStatusOutputStatus<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> AsRef<str> for GetRepoStatusOutputStatus<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for GetRepoStatusOutputStatus<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for GetRepoStatusOutputStatus<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for GetRepoStatusOutputStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for GetRepoStatusOutputStatus<'_> {
    type Output = GetRepoStatusOutputStatus<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            GetRepoStatusOutputStatus::Takendown => GetRepoStatusOutputStatus::Takendown,
            GetRepoStatusOutputStatus::Suspended => GetRepoStatusOutputStatus::Suspended,
            GetRepoStatusOutputStatus::Deleted => GetRepoStatusOutputStatus::Deleted,
            GetRepoStatusOutputStatus::Deactivated => {
                GetRepoStatusOutputStatus::Deactivated
            }
            GetRepoStatusOutputStatus::Desynchronized => {
                GetRepoStatusOutputStatus::Desynchronized
            }
            GetRepoStatusOutputStatus::Throttled => GetRepoStatusOutputStatus::Throttled,
            GetRepoStatusOutputStatus::Other(v) => {
                GetRepoStatusOutputStatus::Other(v.into_static())
            }
        }
    }
}

#[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 GetRepoStatusError<'a> {
    #[serde(rename = "RepoNotFound")]
    RepoNotFound(std::option::Option<jacquard_common::CowStr<'a>>),
}

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

/// Response type for
///com.atproto.sync.getRepoStatus
pub struct GetRepoStatusResponse;
impl jacquard_common::xrpc::XrpcResp for GetRepoStatusResponse {
    const NSID: &'static str = "com.atproto.sync.getRepoStatus";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetRepoStatusOutput<'de>;
    type Err<'de> = GetRepoStatusError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetRepoStatus<'a> {
    const NSID: &'static str = "com.atproto.sync.getRepoStatus";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetRepoStatusResponse;
}

/// Endpoint type for
///com.atproto.sync.getRepoStatus
pub struct GetRepoStatusRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetRepoStatusRequest {
    const PATH: &'static str = "/xrpc/com.atproto.sync.getRepoStatus";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetRepoStatus<'de>;
    type Response = GetRepoStatusResponse;
}