pub mod actions;
pub mod agents;
pub mod commitments;
pub mod error;
pub mod events;
pub mod exchanges;
pub mod flows;
pub mod intents;
pub mod measures;
pub mod plans;
pub mod processes;
pub mod proposals;
pub mod recipes;
pub mod resources;
pub mod storage;
pub mod transfers;
pub mod prelude {
pub use crate::actions::{Action, ActionEffect, ActionType};
pub use crate::agents::{Agent, AgentRelationship, AgentType};
pub use crate::commitments::Commitment;
pub use crate::error::{Error, Result};
pub use crate::events::EconomicEvent;
pub use crate::exchanges::Exchange;
pub use crate::flows::{Flow, FlowType};
pub use crate::intents::Intent;
pub use crate::measures::{Measure, Unit};
pub use crate::plans::Plan;
pub use crate::processes::{Process, ProcessSpecification};
pub use crate::proposals::{Proposal, ProposalStatus, ProposedIntent};
pub use crate::recipes::{RecipeFlow, RecipeProcess, RecipeResource};
pub use crate::resources::{EconomicResource, ResourceSpecification};
pub use crate::storage::Storage;
pub use crate::transfers::{Transfer, TransferType};
}
pub use chrono::{DateTime, Utc};
pub use rust_decimal::Decimal;
#[cfg(feature = "uuid")]
pub use uuid::Uuid;
#[cfg(feature = "uuid")]
pub fn generate_id() -> String {
Uuid::new_v4().to_string()
}
#[cfg(not(feature = "uuid"))]
pub fn generate_id() -> String {
use std::time::{SystemTime, UNIX_EPOCH};
let duration = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default();
format!("id-{}-{}", duration.as_secs(), duration.subsec_nanos())
}
#[cfg(test)]
mod tests {
use super::prelude::*;
use rust_decimal::Decimal;
#[test]
fn test_basic_workflow() {
let agent = Agent::builder()
.id("test-agent")
.name("Test Agent")
.agent_type(AgentType::Person)
.build()
.unwrap();
assert_eq!(agent.name, "Test Agent");
let spec = ResourceSpecification::builder()
.id("test-spec")
.name("Test Resource Type")
.build()
.unwrap();
assert_eq!(spec.name, "Test Resource Type");
let resource = EconomicResource::builder()
.id("test-resource")
.name("Test Resource")
.conforms_to(spec.id.clone())
.primary_accountable(agent.id.clone())
.accounting_quantity(Measure::new(10, Unit::Each))
.build()
.unwrap();
assert_eq!(resource.accounting_quantity.value, Decimal::from(10));
}
}