use crate::regions::Region;
use azure_core::fmt::SafeDebug;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(SafeDebug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[safe(true)]
#[serde(rename_all = "camelCase")]
pub(crate) struct AccountRegion {
pub name: Region,
#[serde(with = "crate::serde::url")]
pub database_account_endpoint: Url,
}
#[derive(SafeDebug, Clone, Serialize, Deserialize)]
#[safe(true)]
#[serde(rename_all = "camelCase")]
pub(crate) struct AccountProperties {
pub writable_locations: Vec<AccountRegion>,
pub readable_locations: Vec<AccountRegion>,
#[serde(default)]
pub enable_per_partition_failover_behavior: bool,
}
#[cfg(test)]
mod tests {
use super::*;
const SAMPLE: &str = r#"{
"_self" : "",
"id" : "test",
"writableLocations" : [ { "name" : "West US 2", "databaseAccountEndpoint" : "https://test-westus2.documents.azure.com:443/" } ],
"readableLocations" : [ { "name" : "West US 2", "databaseAccountEndpoint" : "https://test-westus2.documents.azure.com:443/" } ],
"enableMultipleWriteLocations" : false,
"enable_per_partition_failover_behavior" : true
}"#;
#[test]
fn deserialize_account_props() {
let props: AccountProperties = serde_json::from_str(SAMPLE).expect("deserialize");
assert_eq!(props.writable_locations.len(), 1);
assert_eq!(props.readable_locations.len(), 1);
}
}