use crate::model::{derived_uuid, Id};
pub fn genesis_id(name: &str) -> Id {
let input = format!("grc20:genesis:{}", name);
derived_uuid(input.as_bytes())
}
pub fn language_id(code: &str) -> Id {
let input = format!("grc20:genesis:language:{}", code);
derived_uuid(input.as_bytes())
}
pub mod properties {
use super::*;
lazy_static::lazy_static! {
pub static ref NAME: Id = genesis_id("Name");
pub static ref DESCRIPTION: Id = genesis_id("Description");
pub static ref AVATAR: Id = genesis_id("Avatar");
pub static ref URL: Id = genesis_id("URL");
pub static ref CREATED: Id = genesis_id("Created");
pub static ref MODIFIED: Id = genesis_id("Modified");
}
pub fn name() -> Id {
*NAME
}
pub fn description() -> Id {
*DESCRIPTION
}
pub fn avatar() -> Id {
*AVATAR
}
pub fn url() -> Id {
*URL
}
pub fn created() -> Id {
*CREATED
}
pub fn modified() -> Id {
*MODIFIED
}
}
pub mod types {
use super::*;
lazy_static::lazy_static! {
pub static ref PERSON: Id = genesis_id("Person");
pub static ref ORGANIZATION: Id = genesis_id("Organization");
pub static ref PLACE: Id = genesis_id("Place");
pub static ref TOPIC: Id = genesis_id("Topic");
}
pub fn person() -> Id {
*PERSON
}
pub fn organization() -> Id {
*ORGANIZATION
}
pub fn place() -> Id {
*PLACE
}
pub fn topic() -> Id {
*TOPIC
}
}
pub mod relation_types {
use super::*;
lazy_static::lazy_static! {
pub static ref TYPES: Id = genesis_id("Types");
pub static ref PART_OF: Id = genesis_id("PartOf");
pub static ref RELATED_TO: Id = genesis_id("RelatedTo");
}
pub fn types() -> Id {
*TYPES
}
pub fn part_of() -> Id {
*PART_OF
}
pub fn related_to() -> Id {
*RELATED_TO
}
}
pub mod languages {
use super::*;
lazy_static::lazy_static! {
pub static ref ENGLISH: Id = language_id("en");
pub static ref SPANISH: Id = language_id("es");
pub static ref FRENCH: Id = language_id("fr");
pub static ref GERMAN: Id = language_id("de");
pub static ref CHINESE: Id = language_id("zh");
pub static ref JAPANESE: Id = language_id("ja");
pub static ref KOREAN: Id = language_id("ko");
pub static ref PORTUGUESE: Id = language_id("pt");
pub static ref ITALIAN: Id = language_id("it");
pub static ref RUSSIAN: Id = language_id("ru");
pub static ref ARABIC: Id = language_id("ar");
pub static ref HINDI: Id = language_id("hi");
}
pub fn from_code(code: &str) -> Id {
language_id(code)
}
pub fn english() -> Id {
*ENGLISH
}
pub fn spanish() -> Id {
*SPANISH
}
pub fn french() -> Id {
*FRENCH
}
pub fn german() -> Id {
*GERMAN
}
pub fn chinese() -> Id {
*CHINESE
}
pub fn japanese() -> Id {
*JAPANESE
}
pub fn korean() -> Id {
*KOREAN
}
pub fn portuguese() -> Id {
*PORTUGUESE
}
pub fn italian() -> Id {
*ITALIAN
}
pub fn russian() -> Id {
*RUSSIAN
}
pub fn arabic() -> Id {
*ARABIC
}
pub fn hindi() -> Id {
*HINDI
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::model::format_id;
#[test]
fn test_genesis_id_deterministic() {
let id1 = genesis_id("Name");
let id2 = genesis_id("Name");
assert_eq!(id1, id2);
}
#[test]
fn test_genesis_id_unique() {
let name_id = genesis_id("Name");
let desc_id = genesis_id("Description");
assert_ne!(name_id, desc_id);
}
#[test]
fn test_language_id_deterministic() {
let en1 = language_id("en");
let en2 = language_id("en");
assert_eq!(en1, en2);
}
#[test]
fn test_genesis_id_format() {
let id = genesis_id("Name");
assert_eq!(id[6] & 0xF0, 0x80);
assert_eq!(id[8] & 0xC0, 0x80);
}
#[test]
fn test_static_properties() {
assert_eq!(properties::name(), genesis_id("Name"));
assert_eq!(properties::description(), genesis_id("Description"));
assert_eq!(properties::avatar(), genesis_id("Avatar"));
assert_eq!(properties::url(), genesis_id("URL"));
assert_eq!(properties::created(), genesis_id("Created"));
assert_eq!(properties::modified(), genesis_id("Modified"));
}
#[test]
fn test_static_types() {
assert_eq!(types::person(), genesis_id("Person"));
assert_eq!(types::organization(), genesis_id("Organization"));
assert_eq!(types::place(), genesis_id("Place"));
assert_eq!(types::topic(), genesis_id("Topic"));
}
#[test]
fn test_static_relation_types() {
assert_eq!(relation_types::types(), genesis_id("Types"));
assert_eq!(relation_types::part_of(), genesis_id("PartOf"));
assert_eq!(relation_types::related_to(), genesis_id("RelatedTo"));
}
#[test]
fn test_static_languages() {
assert_eq!(languages::english(), language_id("en"));
assert_eq!(languages::spanish(), language_id("es"));
assert_eq!(languages::from_code("en"), languages::english());
}
#[test]
fn test_print_genesis_ids() {
println!("=== Core Properties ===");
println!("Name: {}", format_id(&properties::name()));
println!("Description: {}", format_id(&properties::description()));
println!("Avatar: {}", format_id(&properties::avatar()));
println!("URL: {}", format_id(&properties::url()));
println!("Created: {}", format_id(&properties::created()));
println!("Modified: {}", format_id(&properties::modified()));
println!("\n=== Core Types ===");
println!("Person: {}", format_id(&types::person()));
println!("Organization: {}", format_id(&types::organization()));
println!("Place: {}", format_id(&types::place()));
println!("Topic: {}", format_id(&types::topic()));
println!("\n=== Core Relation Types ===");
println!("Types: {}", format_id(&relation_types::types()));
println!("PartOf: {}", format_id(&relation_types::part_of()));
println!("RelatedTo: {}", format_id(&relation_types::related_to()));
println!("\n=== Languages ===");
println!("English (en): {}", format_id(&languages::english()));
println!("Spanish (es): {}", format_id(&languages::spanish()));
println!("French (fr): {}", format_id(&languages::french()));
}
}