jacquard-api 0.10.2

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

#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct GetSessionOutput<'a> {
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub active: std::option::Option<bool>,
    #[serde(borrow)]
    pub did: jacquard_common::types::string::Did<'a>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub did_doc: std::option::Option<jacquard_common::types::value::Data<'a>>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub email: std::option::Option<jacquard_common::CowStr<'a>>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub email_auth_factor: std::option::Option<bool>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub email_confirmed: std::option::Option<bool>,
    #[serde(borrow)]
    pub handle: jacquard_common::types::string::Handle<'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.
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub status: std::option::Option<GetSessionOutputStatus<'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 GetSessionOutputStatus<'a> {
    Takendown,
    Suspended,
    Deactivated,
    Other(jacquard_common::CowStr<'a>),
}

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

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

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

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

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

impl<'a> serde::Serialize for GetSessionOutputStatus<'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 GetSessionOutputStatus<'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 GetSessionOutputStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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

/// XRPC request marker type
#[derive(
    Debug,
    Clone,
    Copy,
    PartialEq,
    Eq,
    serde::Serialize,
    serde::Deserialize,
    jacquard_derive::IntoStatic
)]
pub struct GetSession;
/// Response type for
///com.atproto.server.getSession
pub struct GetSessionResponse;
impl jacquard_common::xrpc::XrpcResp for GetSessionResponse {
    const NSID: &'static str = "com.atproto.server.getSession";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetSessionOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl jacquard_common::xrpc::XrpcRequest for GetSession {
    const NSID: &'static str = "com.atproto.server.getSession";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetSessionResponse;
}

/// Endpoint type for
///com.atproto.server.getSession
pub struct GetSessionRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetSessionRequest {
    const PATH: &'static str = "/xrpc/com.atproto.server.getSession";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetSession;
    type Response = GetSessionResponse;
}