jacquard-api 0.12.0-beta.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.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{Did, Tid};
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 GetRepoStatus<S: BosStr = DefaultStr> {
    pub did: Did<S>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct GetRepoStatusOutput<S: BosStr = DefaultStr> {
    pub active: bool,
    pub did: Did<S>,
    ///Optional field, the current rev of the repo, if active=true
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rev: Option<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 = "Option::is_none")]
    pub status: Option<GetRepoStatusOutputStatus<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// 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<S: BosStr = DefaultStr> {
    Takendown,
    Suspended,
    Deleted,
    Deactivated,
    Desynchronized,
    Throttled,
    Other(S),
}

impl<S: BosStr> GetRepoStatusOutputStatus<S> {
    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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "takendown" => Self::Takendown,
            "suspended" => Self::Suspended,
            "deleted" => Self::Deleted,
            "deactivated" => Self::Deactivated,
            "desynchronized" => Self::Desynchronized,
            "throttled" => Self::Throttled,
            _ => Self::Other(s),
        }
    }
}

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

impl<S: BosStr> AsRef<str> for GetRepoStatusOutputStatus<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for GetRepoStatusOutputStatus<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for GetRepoStatusOutputStatus<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for GetRepoStatusOutputStatus<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = GetRepoStatusOutputStatus<S::Output>;
    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())
            }
        }
    }
}

#[derive(
    Serialize, Deserialize, Debug, Clone, PartialEq, Eq, thiserror::Error, miette::Diagnostic,
)]
#[serde(tag = "error", content = "message")]
pub enum GetRepoStatusError {
    #[serde(rename = "RepoNotFound")]
    RepoNotFound(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other {
        error: SmolStr,
        message: Option<SmolStr>,
    },
}

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::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}

/// 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<S: BosStr> = GetRepoStatusOutput<S>;
    type Err = GetRepoStatusError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetRepoStatus<S> {
    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<S: BosStr> = GetRepoStatus<S>;
    type Response = GetRepoStatusResponse;
}

pub mod get_repo_status_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 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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDid<St> {}
    impl<St: State> State for SetDid<St> {
        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<S: BosStr, St: get_repo_status_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Did<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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