Skip to main content

jacquard_api/com_atproto/server/
refresh_session.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: com.atproto.server.refreshSession
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[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, open_union};
17use serde::{Serialize, Deserialize};
18
19#[lexicon]
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(rename_all = "camelCase")]
22pub struct RefreshSessionOutput<'a> {
23    #[serde(borrow)]
24    pub access_jwt: CowStr<'a>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub active: Option<bool>,
27    #[serde(borrow)]
28    pub did: Did<'a>,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    #[serde(borrow)]
31    pub did_doc: Option<Data<'a>>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    #[serde(borrow)]
34    pub email: Option<CowStr<'a>>,
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub email_auth_factor: Option<bool>,
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub email_confirmed: Option<bool>,
39    #[serde(borrow)]
40    pub handle: Handle<'a>,
41    #[serde(borrow)]
42    pub refresh_jwt: CowStr<'a>,
43    ///Hosting status of the account. If not specified, then assume 'active'.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[serde(borrow)]
46    pub status: Option<RefreshSessionOutputStatus<'a>>,
47}
48
49/// Hosting status of the account. If not specified, then assume 'active'.
50
51#[derive(Debug, Clone, PartialEq, Eq, Hash)]
52pub enum RefreshSessionOutputStatus<'a> {
53    Takendown,
54    Suspended,
55    Deactivated,
56    Other(CowStr<'a>),
57}
58
59impl<'a> RefreshSessionOutputStatus<'a> {
60    pub fn as_str(&self) -> &str {
61        match self {
62            Self::Takendown => "takendown",
63            Self::Suspended => "suspended",
64            Self::Deactivated => "deactivated",
65            Self::Other(s) => s.as_ref(),
66        }
67    }
68}
69
70impl<'a> From<&'a str> for RefreshSessionOutputStatus<'a> {
71    fn from(s: &'a str) -> Self {
72        match s {
73            "takendown" => Self::Takendown,
74            "suspended" => Self::Suspended,
75            "deactivated" => Self::Deactivated,
76            _ => Self::Other(CowStr::from(s)),
77        }
78    }
79}
80
81impl<'a> From<String> for RefreshSessionOutputStatus<'a> {
82    fn from(s: String) -> Self {
83        match s.as_str() {
84            "takendown" => Self::Takendown,
85            "suspended" => Self::Suspended,
86            "deactivated" => Self::Deactivated,
87            _ => Self::Other(CowStr::from(s)),
88        }
89    }
90}
91
92impl<'a> core::fmt::Display for RefreshSessionOutputStatus<'a> {
93    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
94        write!(f, "{}", self.as_str())
95    }
96}
97
98impl<'a> AsRef<str> for RefreshSessionOutputStatus<'a> {
99    fn as_ref(&self) -> &str {
100        self.as_str()
101    }
102}
103
104impl<'a> serde::Serialize for RefreshSessionOutputStatus<'a> {
105    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
106    where
107        S: serde::Serializer,
108    {
109        serializer.serialize_str(self.as_str())
110    }
111}
112
113impl<'de, 'a> serde::Deserialize<'de> for RefreshSessionOutputStatus<'a>
114where
115    'de: 'a,
116{
117    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
118    where
119        D: serde::Deserializer<'de>,
120    {
121        let s = <&'de str>::deserialize(deserializer)?;
122        Ok(Self::from(s))
123    }
124}
125
126impl<'a> Default for RefreshSessionOutputStatus<'a> {
127    fn default() -> Self {
128        Self::Other(Default::default())
129    }
130}
131
132impl jacquard_common::IntoStatic for RefreshSessionOutputStatus<'_> {
133    type Output = RefreshSessionOutputStatus<'static>;
134    fn into_static(self) -> Self::Output {
135        match self {
136            RefreshSessionOutputStatus::Takendown => {
137                RefreshSessionOutputStatus::Takendown
138            }
139            RefreshSessionOutputStatus::Suspended => {
140                RefreshSessionOutputStatus::Suspended
141            }
142            RefreshSessionOutputStatus::Deactivated => {
143                RefreshSessionOutputStatus::Deactivated
144            }
145            RefreshSessionOutputStatus::Other(v) => {
146                RefreshSessionOutputStatus::Other(v.into_static())
147            }
148        }
149    }
150}
151
152
153#[open_union]
154#[derive(
155    Serialize,
156    Deserialize,
157    Debug,
158    Clone,
159    PartialEq,
160    Eq,
161    thiserror::Error,
162    miette::Diagnostic,
163    IntoStatic
164)]
165
166#[serde(tag = "error", content = "message")]
167#[serde(bound(deserialize = "'de: 'a"))]
168pub enum RefreshSessionError<'a> {
169    #[serde(rename = "AccountTakedown")]
170    AccountTakedown(Option<CowStr<'a>>),
171    #[serde(rename = "InvalidToken")]
172    InvalidToken(Option<CowStr<'a>>),
173    #[serde(rename = "ExpiredToken")]
174    ExpiredToken(Option<CowStr<'a>>),
175}
176
177impl core::fmt::Display for RefreshSessionError<'_> {
178    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
179        match self {
180            Self::AccountTakedown(msg) => {
181                write!(f, "AccountTakedown")?;
182                if let Some(msg) = msg {
183                    write!(f, ": {}", msg)?;
184                }
185                Ok(())
186            }
187            Self::InvalidToken(msg) => {
188                write!(f, "InvalidToken")?;
189                if let Some(msg) = msg {
190                    write!(f, ": {}", msg)?;
191                }
192                Ok(())
193            }
194            Self::ExpiredToken(msg) => {
195                write!(f, "ExpiredToken")?;
196                if let Some(msg) = msg {
197                    write!(f, ": {}", msg)?;
198                }
199                Ok(())
200            }
201            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
202        }
203    }
204}
205
206/// XRPC request marker type.
207
208#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Copy)]
209pub struct RefreshSession;
210/// Response type for com.atproto.server.refreshSession
211pub struct RefreshSessionResponse;
212impl jacquard_common::xrpc::XrpcResp for RefreshSessionResponse {
213    const NSID: &'static str = "com.atproto.server.refreshSession";
214    const ENCODING: &'static str = "application/json";
215    type Output<'de> = RefreshSessionOutput<'de>;
216    type Err<'de> = RefreshSessionError<'de>;
217}
218
219impl jacquard_common::xrpc::XrpcRequest for RefreshSession {
220    const NSID: &'static str = "com.atproto.server.refreshSession";
221    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
222        "application/json",
223    );
224    type Response = RefreshSessionResponse;
225}
226
227/// Endpoint type for com.atproto.server.refreshSession
228pub struct RefreshSessionRequest;
229impl jacquard_common::xrpc::XrpcEndpoint for RefreshSessionRequest {
230    const PATH: &'static str = "/xrpc/com.atproto.server.refreshSession";
231    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
232        "application/json",
233    );
234    type Request<'de> = RefreshSession;
235    type Response = RefreshSessionResponse;
236}