jacquard_api/com_atproto/server/
get_session.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::{Did, Handle};
15use jacquard_common::types::value::Data;
16use jacquard_derive::{IntoStatic, lexicon};
17use serde::{Serialize, Deserialize};
18
19#[lexicon]
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(rename_all = "camelCase")]
22pub struct GetSessionOutput<'a> {
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub active: Option<bool>,
25 #[serde(borrow)]
26 pub did: Did<'a>,
27 #[serde(skip_serializing_if = "Option::is_none")]
28 #[serde(borrow)]
29 pub did_doc: Option<Data<'a>>,
30 #[serde(skip_serializing_if = "Option::is_none")]
31 #[serde(borrow)]
32 pub email: Option<CowStr<'a>>,
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub email_auth_factor: Option<bool>,
35 #[serde(skip_serializing_if = "Option::is_none")]
36 pub email_confirmed: Option<bool>,
37 #[serde(borrow)]
38 pub handle: Handle<'a>,
39 #[serde(skip_serializing_if = "Option::is_none")]
41 #[serde(borrow)]
42 pub status: Option<GetSessionOutputStatus<'a>>,
43}
44
45#[derive(Debug, Clone, PartialEq, Eq, Hash)]
48pub enum GetSessionOutputStatus<'a> {
49 Takendown,
50 Suspended,
51 Deactivated,
52 Other(CowStr<'a>),
53}
54
55impl<'a> GetSessionOutputStatus<'a> {
56 pub fn as_str(&self) -> &str {
57 match self {
58 Self::Takendown => "takendown",
59 Self::Suspended => "suspended",
60 Self::Deactivated => "deactivated",
61 Self::Other(s) => s.as_ref(),
62 }
63 }
64}
65
66impl<'a> From<&'a str> for GetSessionOutputStatus<'a> {
67 fn from(s: &'a str) -> Self {
68 match s {
69 "takendown" => Self::Takendown,
70 "suspended" => Self::Suspended,
71 "deactivated" => Self::Deactivated,
72 _ => Self::Other(CowStr::from(s)),
73 }
74 }
75}
76
77impl<'a> From<String> for GetSessionOutputStatus<'a> {
78 fn from(s: String) -> Self {
79 match s.as_str() {
80 "takendown" => Self::Takendown,
81 "suspended" => Self::Suspended,
82 "deactivated" => Self::Deactivated,
83 _ => Self::Other(CowStr::from(s)),
84 }
85 }
86}
87
88impl<'a> core::fmt::Display for GetSessionOutputStatus<'a> {
89 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
90 write!(f, "{}", self.as_str())
91 }
92}
93
94impl<'a> AsRef<str> for GetSessionOutputStatus<'a> {
95 fn as_ref(&self) -> &str {
96 self.as_str()
97 }
98}
99
100impl<'a> serde::Serialize for GetSessionOutputStatus<'a> {
101 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
102 where
103 S: serde::Serializer,
104 {
105 serializer.serialize_str(self.as_str())
106 }
107}
108
109impl<'de, 'a> serde::Deserialize<'de> for GetSessionOutputStatus<'a>
110where
111 'de: 'a,
112{
113 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
114 where
115 D: serde::Deserializer<'de>,
116 {
117 let s = <&'de str>::deserialize(deserializer)?;
118 Ok(Self::from(s))
119 }
120}
121
122impl<'a> Default for GetSessionOutputStatus<'a> {
123 fn default() -> Self {
124 Self::Other(Default::default())
125 }
126}
127
128impl jacquard_common::IntoStatic for GetSessionOutputStatus<'_> {
129 type Output = GetSessionOutputStatus<'static>;
130 fn into_static(self) -> Self::Output {
131 match self {
132 GetSessionOutputStatus::Takendown => GetSessionOutputStatus::Takendown,
133 GetSessionOutputStatus::Suspended => GetSessionOutputStatus::Suspended,
134 GetSessionOutputStatus::Deactivated => GetSessionOutputStatus::Deactivated,
135 GetSessionOutputStatus::Other(v) => {
136 GetSessionOutputStatus::Other(v.into_static())
137 }
138 }
139 }
140}
141
142#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Copy)]
145pub struct GetSession;
146pub struct GetSessionResponse;
148impl jacquard_common::xrpc::XrpcResp for GetSessionResponse {
149 const NSID: &'static str = "com.atproto.server.getSession";
150 const ENCODING: &'static str = "application/json";
151 type Output<'de> = GetSessionOutput<'de>;
152 type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
153}
154
155impl jacquard_common::xrpc::XrpcRequest for GetSession {
156 const NSID: &'static str = "com.atproto.server.getSession";
157 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
158 type Response = GetSessionResponse;
159}
160
161pub struct GetSessionRequest;
163impl jacquard_common::xrpc::XrpcEndpoint for GetSessionRequest {
164 const PATH: &'static str = "/xrpc/com.atproto.server.getSession";
165 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
166 type Request<'de> = GetSession;
167 type Response = GetSessionResponse;
168}