use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;
use uuid::Uuid;
macro_rules! uuid_newtype {
($name:ident) => {
#[doc = concat!("Strongly typed UUID wrapper for `", stringify!($name), "` resources.")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct $name(pub Uuid);
impl fmt::Display for $name {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl From<Uuid> for $name {
fn from(value: Uuid) -> Self {
Self(value)
}
}
impl From<$name> for Uuid {
fn from(value: $name) -> Self {
value.0
}
}
impl FromStr for $name {
type Err = uuid::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(Uuid::parse_str(s)?))
}
}
};
}
uuid_newtype!(CustomerId);
uuid_newtype!(InvoiceId);
uuid_newtype!(LedgerAccountId);
uuid_newtype!(ProjectId);
uuid_newtype!(ExpenseId);
uuid_newtype!(OrganizationId);