dintero_accounts/
types.rs

1//! Type definitions for accounts.
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Account {
8    pub id: String,
9    pub name: String,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub organization_number: Option<String>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub email: Option<String>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub phone: Option<String>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub country: Option<String>,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub currency: Option<String>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub settings: Option<AccountSettings>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub created_at: Option<String>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub updated_at: Option<String>,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct AccountSettings {
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub features: Option<HashMap<String, bool>>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub payment_methods: Option<Vec<String>>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub webhooks: Option<WebhookSettings>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct WebhookSettings {
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub url: Option<String>,
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub secret: Option<String>,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub events: Option<Vec<String>>,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct Profile {
50    pub id: String,
51    pub name: String,
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub account_id: Option<String>,
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub logo_url: Option<String>,
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub settings: Option<ProfileSettings>,
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub created_at: Option<String>,
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub updated_at: Option<String>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct ProfileSettings {
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub branding: Option<BrandingSettings>,
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub checkout: Option<CheckoutSettings>,
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct BrandingSettings {
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub colors: Option<HashMap<String, String>>,
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub logo: Option<String>,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct CheckoutSettings {
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub terms_url: Option<String>,
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub privacy_url: Option<String>,
86}
87
88#[derive(Debug, Default, Clone)]
89pub struct UpdateAccountRequest {
90    name: Option<String>,
91    email: Option<String>,
92    phone: Option<String>,
93    settings: Option<AccountSettings>,
94}
95
96impl UpdateAccountRequest {
97    pub fn new() -> Self {
98        Self::default()
99    }
100
101    pub fn name(mut self, name: impl Into<String>) -> Self {
102        self.name = Some(name.into());
103        self
104    }
105
106    pub fn email(mut self, email: impl Into<String>) -> Self {
107        self.email = Some(email.into());
108        self
109    }
110
111    pub fn phone(mut self, phone: impl Into<String>) -> Self {
112        self.phone = Some(phone.into());
113        self
114    }
115
116    pub fn settings(mut self, settings: AccountSettings) -> Self {
117        self.settings = Some(settings);
118        self
119    }
120
121    pub fn build(self) -> serde_json::Value {
122        serde_json::json!({
123            "name": self.name,
124            "email": self.email,
125            "phone": self.phone,
126            "settings": self.settings,
127        })
128    }
129}
130
131#[derive(Debug, Default, Clone)]
132pub struct UpdateProfileRequest {
133    name: Option<String>,
134    logo_url: Option<String>,
135    settings: Option<ProfileSettings>,
136}
137
138impl UpdateProfileRequest {
139    pub fn new() -> Self {
140        Self::default()
141    }
142
143    pub fn name(mut self, name: impl Into<String>) -> Self {
144        self.name = Some(name.into());
145        self
146    }
147
148    pub fn logo_url(mut self, url: impl Into<String>) -> Self {
149        self.logo_url = Some(url.into());
150        self
151    }
152
153    pub fn settings(mut self, settings: ProfileSettings) -> Self {
154        self.settings = Some(settings);
155        self
156    }
157
158    pub fn build(self) -> serde_json::Value {
159        serde_json::json!({
160            "name": self.name,
161            "logo_url": self.logo_url,
162            "settings": self.settings,
163        })
164    }
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize)]
168pub struct Session {
169    pub id: String,
170    #[serde(skip_serializing_if = "Option::is_none")]
171    pub account_id: Option<String>,
172    #[serde(skip_serializing_if = "Option::is_none")]
173    pub profile_id: Option<String>,
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub user_id: Option<String>,
176    #[serde(skip_serializing_if = "Option::is_none")]
177    pub expires_at: Option<String>,
178    #[serde(skip_serializing_if = "Option::is_none")]
179    pub created_at: Option<String>,
180}
181
182#[derive(Debug, Clone, Serialize, Deserialize)]
183pub struct AccountList {
184    pub accounts: Vec<Account>,
185    #[serde(skip_serializing_if = "Option::is_none")]
186    pub next_page_token: Option<String>,
187}
188
189#[derive(Debug, Clone, Serialize, Deserialize)]
190pub struct ProfileList {
191    pub profiles: Vec<Profile>,
192    #[serde(skip_serializing_if = "Option::is_none")]
193    pub next_page_token: Option<String>,
194}