Skip to main content

xcom_rs/auth/
models.rs

1use serde::{Deserialize, Serialize};
2
3/// Action to be performed during import
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
5#[serde(rename_all = "lowercase")]
6pub enum ImportAction {
7    /// Create new authentication entry
8    Create,
9    /// Update existing authentication entry
10    Update,
11    /// Skip - no changes needed
12    Skip,
13    /// Failed with error
14    Fail,
15}
16
17/// Plan for a single import operation
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct ImportPlan {
20    /// Action to be performed
21    pub action: ImportAction,
22    /// Optional reason (required for Fail action)
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub reason: Option<String>,
25    /// Whether this is a dry-run
26    #[serde(rename = "dryRun")]
27    pub dry_run: bool,
28}
29
30impl ImportPlan {
31    /// Create a plan for creating new auth
32    pub fn create(dry_run: bool) -> Self {
33        Self {
34            action: ImportAction::Create,
35            reason: None,
36            dry_run,
37        }
38    }
39
40    /// Create a plan for updating existing auth
41    pub fn update(dry_run: bool) -> Self {
42        Self {
43            action: ImportAction::Update,
44            reason: None,
45            dry_run,
46        }
47    }
48
49    /// Create a plan for skipping (no changes)
50    pub fn skip(reason: String, dry_run: bool) -> Self {
51        Self {
52            action: ImportAction::Skip,
53            reason: Some(reason),
54            dry_run,
55        }
56    }
57
58    /// Create a plan for failed import
59    pub fn fail(reason: String, dry_run: bool) -> Self {
60        Self {
61            action: ImportAction::Fail,
62            reason: Some(reason),
63            dry_run,
64        }
65    }
66}
67
68/// Authentication status response
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct AuthStatus {
71    pub authenticated: bool,
72    #[serde(rename = "authMode", skip_serializing_if = "Option::is_none")]
73    pub auth_mode: Option<String>,
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub scopes: Option<Vec<String>>,
76    #[serde(rename = "nextSteps", skip_serializing_if = "Option::is_none")]
77    pub next_steps: Option<Vec<String>>,
78}
79
80impl AuthStatus {
81    /// Create an unauthenticated status with next steps
82    pub fn unauthenticated(next_steps: Vec<String>) -> Self {
83        Self {
84            authenticated: false,
85            auth_mode: None,
86            scopes: None,
87            next_steps: Some(next_steps),
88        }
89    }
90
91    /// Create an authenticated status
92    pub fn authenticated(auth_mode: String, scopes: Vec<String>) -> Self {
93        Self {
94            authenticated: true,
95            auth_mode: Some(auth_mode),
96            scopes: Some(scopes),
97            next_steps: None,
98        }
99    }
100}
101
102/// Authentication token data for export/import
103#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
104pub struct AuthToken {
105    #[serde(rename = "accessToken")]
106    pub access_token: String,
107    #[serde(rename = "tokenType")]
108    pub token_type: String,
109    #[serde(rename = "expiresAt", skip_serializing_if = "Option::is_none")]
110    pub expires_at: Option<i64>,
111    pub scopes: Vec<String>,
112}