use serde_json::Value;
pub fn iso_now() -> String {
chrono::Utc::now()
.format("%Y-%m-%dT%H:%M:%S%.3fZ")
.to_string()
}
pub fn current_year() -> i32 {
chrono::Utc::now()
.format("%Y")
.to_string()
.parse()
.unwrap_or(2013)
}
pub fn hash_str(s: &str) -> u64 {
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
for b in s.as_bytes() {
h ^= u64::from(*b);
h = h.wrapping_mul(0x0000_0100_0000_01b3);
}
h
}
pub fn hex32() -> String {
uuid::Uuid::new_v4().simple().to_string()
}
pub fn new_case_id(account: &str, year: i32) -> String {
let tail = &hex32()[..16];
format!("case-{account}-{year}-{tail}")
}
pub fn display_id(case_id: &str) -> String {
let n = hash_str(case_id) % 9_000_000_000 + 1_000_000_000;
n.to_string()
}
pub fn new_attachment_set_id() -> String {
format!("as-{}", hex32())
}
pub fn new_attachment_id() -> String {
format!("attachment-{}", hex32())
}
pub fn str_member<'a>(body: &'a Value, name: &str) -> Option<&'a str> {
body.get(name).and_then(Value::as_str)
}