use derive_more::{AsRef, Display, From, FromStr, Into};
use uuid::Uuid;
use crate::utils::ExampleData;
#[derive(
AsRef, Display, From, FromStr, Into, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[cfg_attr(
feature = "diesel",
derive(
opentalk_diesel_newtype::DieselNewtype,
diesel::expression::AsExpression,
diesel::deserialize::FromSqlRow
)
)]
#[cfg_attr(feature="diesel", diesel(sql_type = diesel::sql_types::Uuid))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "utoipa",
derive(utoipa::ToSchema),
schema(example = json!(AssetId::example_data().to_string()))
)]
#[cfg_attr(feature = "typescript", derive(ts_rs::TS), ts(export_to = "common/"))]
pub struct AssetId(Uuid);
impl AssetId {
pub const fn nil() -> Self {
Self(Uuid::nil())
}
pub const fn from_u128(id: u128) -> Self {
Self(Uuid::from_u128(id))
}
#[cfg(feature = "rand")]
pub fn generate() -> Self {
Self(Uuid::new_v4())
}
}
impl ExampleData for AssetId {
fn example_data() -> Self {
AssetId::from_u128(0xaabbcc00)
}
}