1use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
12pub enum LoginState {
13 #[default]
14 #[serde(rename = "SignIn")]
15 SignIn,
16 #[serde(rename = "SignUp")]
17 SignUp,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
23pub enum DialogType {
24 #[default]
25 #[serde(rename = "AccountChooser")]
26 AccountChooser,
27 #[serde(rename = "AutoReauthn")]
28 AutoReauthn,
29 #[serde(rename = "ConfirmIdpLogin")]
30 ConfirmIdpLogin,
31 #[serde(rename = "Error")]
32 Error,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
38pub enum DialogButton {
39 #[default]
40 #[serde(rename = "ConfirmIdpLoginContinue")]
41 ConfirmIdpLoginContinue,
42 #[serde(rename = "ErrorGotIt")]
43 ErrorGotIt,
44 #[serde(rename = "ErrorMoreDetails")]
45 ErrorMoreDetails,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
51pub enum AccountUrlType {
52 #[default]
53 #[serde(rename = "TermsOfService")]
54 TermsOfService,
55 #[serde(rename = "PrivacyPolicy")]
56 PrivacyPolicy,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize, Default)]
62#[serde(rename_all = "camelCase")]
63pub struct Account<'a> {
64 #[serde(rename = "accountId")]
65 account_id: Cow<'a, str>,
66 email: Cow<'a, str>,
67 name: Cow<'a, str>,
68 #[serde(rename = "givenName")]
69 given_name: Cow<'a, str>,
70 #[serde(rename = "pictureUrl")]
71 picture_url: Cow<'a, str>,
72 #[serde(rename = "idpConfigUrl")]
73 idp_config_url: Cow<'a, str>,
74 #[serde(rename = "idpLoginUrl")]
75 idp_login_url: Cow<'a, str>,
76 #[serde(rename = "loginState")]
77 login_state: LoginState,
78 #[serde(skip_serializing_if = "Option::is_none", rename = "termsOfServiceUrl")]
80 terms_of_service_url: Option<Cow<'a, str>>,
81 #[serde(skip_serializing_if = "Option::is_none", rename = "privacyPolicyUrl")]
82 privacy_policy_url: Option<Cow<'a, str>>,
83}
84
85impl<'a> Account<'a> {
86 pub fn builder(account_id: impl Into<Cow<'a, str>>, email: impl Into<Cow<'a, str>>, name: impl Into<Cow<'a, str>>, given_name: impl Into<Cow<'a, str>>, picture_url: impl Into<Cow<'a, str>>, idp_config_url: impl Into<Cow<'a, str>>, idp_login_url: impl Into<Cow<'a, str>>, login_state: impl Into<LoginState>) -> AccountBuilder<'a> {
96 AccountBuilder {
97 account_id: account_id.into(),
98 email: email.into(),
99 name: name.into(),
100 given_name: given_name.into(),
101 picture_url: picture_url.into(),
102 idp_config_url: idp_config_url.into(),
103 idp_login_url: idp_login_url.into(),
104 login_state: login_state.into(),
105 terms_of_service_url: None,
106 privacy_policy_url: None,
107 }
108 }
109 pub fn account_id(&self) -> &str { self.account_id.as_ref() }
110 pub fn email(&self) -> &str { self.email.as_ref() }
111 pub fn name(&self) -> &str { self.name.as_ref() }
112 pub fn given_name(&self) -> &str { self.given_name.as_ref() }
113 pub fn picture_url(&self) -> &str { self.picture_url.as_ref() }
114 pub fn idp_config_url(&self) -> &str { self.idp_config_url.as_ref() }
115 pub fn idp_login_url(&self) -> &str { self.idp_login_url.as_ref() }
116 pub fn login_state(&self) -> &LoginState { &self.login_state }
117 pub fn terms_of_service_url(&self) -> Option<&str> { self.terms_of_service_url.as_deref() }
119 pub fn privacy_policy_url(&self) -> Option<&str> { self.privacy_policy_url.as_deref() }
120}
121
122
123pub struct AccountBuilder<'a> {
124 account_id: Cow<'a, str>,
125 email: Cow<'a, str>,
126 name: Cow<'a, str>,
127 given_name: Cow<'a, str>,
128 picture_url: Cow<'a, str>,
129 idp_config_url: Cow<'a, str>,
130 idp_login_url: Cow<'a, str>,
131 login_state: LoginState,
132 terms_of_service_url: Option<Cow<'a, str>>,
133 privacy_policy_url: Option<Cow<'a, str>>,
134}
135
136impl<'a> AccountBuilder<'a> {
137 pub fn terms_of_service_url(mut self, terms_of_service_url: impl Into<Cow<'a, str>>) -> Self { self.terms_of_service_url = Some(terms_of_service_url.into()); self }
139 pub fn privacy_policy_url(mut self, privacy_policy_url: impl Into<Cow<'a, str>>) -> Self { self.privacy_policy_url = Some(privacy_policy_url.into()); self }
140 pub fn build(self) -> Account<'a> {
141 Account {
142 account_id: self.account_id,
143 email: self.email,
144 name: self.name,
145 given_name: self.given_name,
146 picture_url: self.picture_url,
147 idp_config_url: self.idp_config_url,
148 idp_login_url: self.idp_login_url,
149 login_state: self.login_state,
150 terms_of_service_url: self.terms_of_service_url,
151 privacy_policy_url: self.privacy_policy_url,
152 }
153 }
154}
155
156
157#[derive(Debug, Clone, Serialize, Deserialize, Default)]
158#[serde(rename_all = "camelCase")]
159pub struct EnableParams {
160 #[serde(skip_serializing_if = "Option::is_none", rename = "disableRejectionDelay")]
164 disable_rejection_delay: Option<bool>,
165}
166
167impl EnableParams {
168 pub fn builder() -> EnableParamsBuilder {
170 EnableParamsBuilder {
171 disable_rejection_delay: None,
172 }
173 }
174 pub fn disable_rejection_delay(&self) -> Option<bool> { self.disable_rejection_delay }
178}
179
180#[derive(Default)]
181pub struct EnableParamsBuilder {
182 disable_rejection_delay: Option<bool>,
183}
184
185impl EnableParamsBuilder {
186 pub fn disable_rejection_delay(mut self, disable_rejection_delay: bool) -> Self { self.disable_rejection_delay = Some(disable_rejection_delay); self }
190 pub fn build(self) -> EnableParams {
191 EnableParams {
192 disable_rejection_delay: self.disable_rejection_delay,
193 }
194 }
195}
196
197impl EnableParams { pub const METHOD: &'static str = "FedCm.enable"; }
198
199impl<'a> crate::CdpCommand<'a> for EnableParams {
200 const METHOD: &'static str = "FedCm.enable";
201 type Response = crate::EmptyReturns;
202}
203
204#[derive(Debug, Clone, Serialize, Deserialize, Default)]
205pub struct DisableParams {}
206
207impl DisableParams { pub const METHOD: &'static str = "FedCm.disable"; }
208
209impl<'a> crate::CdpCommand<'a> for DisableParams {
210 const METHOD: &'static str = "FedCm.disable";
211 type Response = crate::EmptyReturns;
212}
213
214
215#[derive(Debug, Clone, Serialize, Deserialize, Default)]
216#[serde(rename_all = "camelCase")]
217pub struct SelectAccountParams<'a> {
218 #[serde(rename = "dialogId")]
219 dialog_id: Cow<'a, str>,
220 #[serde(rename = "accountIndex")]
221 account_index: u64,
222}
223
224impl<'a> SelectAccountParams<'a> {
225 pub fn builder(dialog_id: impl Into<Cow<'a, str>>, account_index: u64) -> SelectAccountParamsBuilder<'a> {
229 SelectAccountParamsBuilder {
230 dialog_id: dialog_id.into(),
231 account_index: account_index,
232 }
233 }
234 pub fn dialog_id(&self) -> &str { self.dialog_id.as_ref() }
235 pub fn account_index(&self) -> u64 { self.account_index }
236}
237
238
239pub struct SelectAccountParamsBuilder<'a> {
240 dialog_id: Cow<'a, str>,
241 account_index: u64,
242}
243
244impl<'a> SelectAccountParamsBuilder<'a> {
245 pub fn build(self) -> SelectAccountParams<'a> {
246 SelectAccountParams {
247 dialog_id: self.dialog_id,
248 account_index: self.account_index,
249 }
250 }
251}
252
253impl<'a> SelectAccountParams<'a> { pub const METHOD: &'static str = "FedCm.selectAccount"; }
254
255impl<'a> crate::CdpCommand<'a> for SelectAccountParams<'a> {
256 const METHOD: &'static str = "FedCm.selectAccount";
257 type Response = crate::EmptyReturns;
258}
259
260
261#[derive(Debug, Clone, Serialize, Deserialize, Default)]
262#[serde(rename_all = "camelCase")]
263pub struct ClickDialogButtonParams<'a> {
264 #[serde(rename = "dialogId")]
265 dialog_id: Cow<'a, str>,
266 #[serde(rename = "dialogButton")]
267 dialog_button: DialogButton,
268}
269
270impl<'a> ClickDialogButtonParams<'a> {
271 pub fn builder(dialog_id: impl Into<Cow<'a, str>>, dialog_button: impl Into<DialogButton>) -> ClickDialogButtonParamsBuilder<'a> {
275 ClickDialogButtonParamsBuilder {
276 dialog_id: dialog_id.into(),
277 dialog_button: dialog_button.into(),
278 }
279 }
280 pub fn dialog_id(&self) -> &str { self.dialog_id.as_ref() }
281 pub fn dialog_button(&self) -> &DialogButton { &self.dialog_button }
282}
283
284
285pub struct ClickDialogButtonParamsBuilder<'a> {
286 dialog_id: Cow<'a, str>,
287 dialog_button: DialogButton,
288}
289
290impl<'a> ClickDialogButtonParamsBuilder<'a> {
291 pub fn build(self) -> ClickDialogButtonParams<'a> {
292 ClickDialogButtonParams {
293 dialog_id: self.dialog_id,
294 dialog_button: self.dialog_button,
295 }
296 }
297}
298
299impl<'a> ClickDialogButtonParams<'a> { pub const METHOD: &'static str = "FedCm.clickDialogButton"; }
300
301impl<'a> crate::CdpCommand<'a> for ClickDialogButtonParams<'a> {
302 const METHOD: &'static str = "FedCm.clickDialogButton";
303 type Response = crate::EmptyReturns;
304}
305
306
307#[derive(Debug, Clone, Serialize, Deserialize, Default)]
308#[serde(rename_all = "camelCase")]
309pub struct OpenUrlParams<'a> {
310 #[serde(rename = "dialogId")]
311 dialog_id: Cow<'a, str>,
312 #[serde(rename = "accountIndex")]
313 account_index: u64,
314 #[serde(rename = "accountUrlType")]
315 account_url_type: AccountUrlType,
316}
317
318impl<'a> OpenUrlParams<'a> {
319 pub fn builder(dialog_id: impl Into<Cow<'a, str>>, account_index: u64, account_url_type: impl Into<AccountUrlType>) -> OpenUrlParamsBuilder<'a> {
324 OpenUrlParamsBuilder {
325 dialog_id: dialog_id.into(),
326 account_index: account_index,
327 account_url_type: account_url_type.into(),
328 }
329 }
330 pub fn dialog_id(&self) -> &str { self.dialog_id.as_ref() }
331 pub fn account_index(&self) -> u64 { self.account_index }
332 pub fn account_url_type(&self) -> &AccountUrlType { &self.account_url_type }
333}
334
335
336pub struct OpenUrlParamsBuilder<'a> {
337 dialog_id: Cow<'a, str>,
338 account_index: u64,
339 account_url_type: AccountUrlType,
340}
341
342impl<'a> OpenUrlParamsBuilder<'a> {
343 pub fn build(self) -> OpenUrlParams<'a> {
344 OpenUrlParams {
345 dialog_id: self.dialog_id,
346 account_index: self.account_index,
347 account_url_type: self.account_url_type,
348 }
349 }
350}
351
352impl<'a> OpenUrlParams<'a> { pub const METHOD: &'static str = "FedCm.openUrl"; }
353
354impl<'a> crate::CdpCommand<'a> for OpenUrlParams<'a> {
355 const METHOD: &'static str = "FedCm.openUrl";
356 type Response = crate::EmptyReturns;
357}
358
359
360#[derive(Debug, Clone, Serialize, Deserialize, Default)]
361#[serde(rename_all = "camelCase")]
362pub struct DismissDialogParams<'a> {
363 #[serde(rename = "dialogId")]
364 dialog_id: Cow<'a, str>,
365 #[serde(skip_serializing_if = "Option::is_none", rename = "triggerCooldown")]
366 trigger_cooldown: Option<bool>,
367}
368
369impl<'a> DismissDialogParams<'a> {
370 pub fn builder(dialog_id: impl Into<Cow<'a, str>>) -> DismissDialogParamsBuilder<'a> {
373 DismissDialogParamsBuilder {
374 dialog_id: dialog_id.into(),
375 trigger_cooldown: None,
376 }
377 }
378 pub fn dialog_id(&self) -> &str { self.dialog_id.as_ref() }
379 pub fn trigger_cooldown(&self) -> Option<bool> { self.trigger_cooldown }
380}
381
382
383pub struct DismissDialogParamsBuilder<'a> {
384 dialog_id: Cow<'a, str>,
385 trigger_cooldown: Option<bool>,
386}
387
388impl<'a> DismissDialogParamsBuilder<'a> {
389 pub fn trigger_cooldown(mut self, trigger_cooldown: bool) -> Self { self.trigger_cooldown = Some(trigger_cooldown); self }
390 pub fn build(self) -> DismissDialogParams<'a> {
391 DismissDialogParams {
392 dialog_id: self.dialog_id,
393 trigger_cooldown: self.trigger_cooldown,
394 }
395 }
396}
397
398impl<'a> DismissDialogParams<'a> { pub const METHOD: &'static str = "FedCm.dismissDialog"; }
399
400impl<'a> crate::CdpCommand<'a> for DismissDialogParams<'a> {
401 const METHOD: &'static str = "FedCm.dismissDialog";
402 type Response = crate::EmptyReturns;
403}
404
405#[derive(Debug, Clone, Serialize, Deserialize, Default)]
406pub struct ResetCooldownParams {}
407
408impl ResetCooldownParams { pub const METHOD: &'static str = "FedCm.resetCooldown"; }
409
410impl<'a> crate::CdpCommand<'a> for ResetCooldownParams {
411 const METHOD: &'static str = "FedCm.resetCooldown";
412 type Response = crate::EmptyReturns;
413}