use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Account {
pub status: AccountStatus,
pub contact: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub orders: Option<String>,
#[serde(
rename = "termsOfServiceAgreed",
skip_serializing_if = "Option::is_none"
)]
pub terms_of_service_agreed: Option<bool>,
#[serde(
rename = "externalAccountBinding",
skip_serializing_if = "Option::is_none"
)]
pub external_account_binding: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum AccountStatus {
Valid,
Deactivated,
Revoked,
}
#[derive(Debug, Clone, Serialize)]
pub struct AccountCreate {
pub contact: Vec<String>,
#[serde(rename = "termsOfServiceAgreed")]
pub terms_of_service_agreed: bool,
#[serde(
rename = "externalAccountBinding",
skip_serializing_if = "Option::is_none"
)]
pub external_account_binding: Option<serde_json::Value>,
}
impl AccountCreate {
pub fn new(contact: Vec<String>, terms_of_service_agreed: bool) -> Self {
Self {
contact,
terms_of_service_agreed,
external_account_binding: None,
}
}
pub fn with_eab(mut self, eab: serde_json::Value) -> Self {
self.external_account_binding = Some(eab);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_account_create() {
let account_create = AccountCreate::new(vec!["mailto:admin@example.com".to_string()], true);
assert_eq!(account_create.contact.len(), 1);
assert!(account_create.terms_of_service_agreed);
assert!(account_create.external_account_binding.is_none());
}
#[test]
fn test_account_status_serialization() {
let status = AccountStatus::Valid;
let json = serde_json::to_string(&status).unwrap();
assert_eq!(json, "\"valid\"");
}
}