rvf 0.1.0

Rust implementation of the ValueFlows vocabulary for distributed economic networks
Documentation
//! # rvf - Rust ValueFlows Implementation
//!
//! Rust implementation of the [ValueFlows](https://www.valueflo.ws/)
//! vocabulary for distributed economic networks.
//!
//! ValueFlows is a vocabulary for the distributed economic networks of the next economy,
//! designed to coordinate the creation, distribution, and exchange of economic resources.
//!
//! ## Core Concepts
//!
//! The library implements the REA (Resources, Events, Agents) ontology with the following
//! core concepts:
//!
//! - **Agents**: People, organizations, or ecological agents that participate in economic activity
//! - **Resources**: Economic resources that can be created, transferred, or consumed
//! - **Events**: Economic events that record what actually happened
//! - **Commitments**: Promises/plans for future events
//! - **Intents**: Offers and requests that may lead to commitments
//! - **Processes**: Transformations that take inputs and produce outputs
//! - **Actions**: Define what a flow does (produce, consume, transfer, etc.)
//!
//! ## Features
//!
//! - `serde` (default): Enable serialization/deserialization support
//! - `uuid` (default): Enable UUID generation for identifiers
//! - `async`: Enable async support for storage backends
//! - `full`: Enable all features
//!
//! ## Example
//!
//! ```rust
//! use rvf::prelude::*;
//!
//! // Create an agent
//! let farmer = Agent::builder()
//!     .id("agent-001")
//!     .name("Local Farm")
//!     .agent_type(AgentType::Organization)
//!     .build()
//!     .unwrap();
//!
//! // Create a resource specification
//! let tomato_spec = ResourceSpecification::builder()
//!     .id("spec-001")
//!     .name("Organic Tomatoes")
//!     .build()
//!     .unwrap();
//!
//! // Create an economic resource
//! let tomatoes = EconomicResource::builder()
//!     .id("resource-001")
//!     .name("Farm Tomatoes Batch #1")
//!     .conforms_to(tomato_spec.id.clone())
//!     .primary_accountable(farmer.id.clone())
//!     .accounting_quantity(Measure::new(100, Unit::Kilogram))
//!     .build()
//!     .unwrap();
//! ```
//!
//! ## Architecture
//!
//! The library is designed to be:
//!
//! - **Storage-agnostic**: Use the provided `Storage` trait to implement any backend
//! - **P2P-ready**: All types are serializable and designed for distributed systems
//! - **Type-safe**: Leverages Rust's type system to prevent invalid states
//! - **Extensible**: Easy to add custom classifications and behaviors

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;

/// Re-exports of commonly used types
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};
}

// Re-export chrono types for convenience
pub use chrono::{DateTime, Utc};
pub use rust_decimal::Decimal;

#[cfg(feature = "uuid")]
pub use uuid::Uuid;

/// Generate a new unique identifier
#[cfg(feature = "uuid")]
pub fn generate_id() -> String {
    Uuid::new_v4().to_string()
}

/// Generate a new unique identifier (fallback when uuid feature is disabled)
#[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() {
        // Create an agent
        let agent = Agent::builder()
            .id("test-agent")
            .name("Test Agent")
            .agent_type(AgentType::Person)
            .build()
            .unwrap();

        assert_eq!(agent.name, "Test Agent");

        // Create a resource specification
        let spec = ResourceSpecification::builder()
            .id("test-spec")
            .name("Test Resource Type")
            .build()
            .unwrap();

        assert_eq!(spec.name, "Test Resource Type");

        // Create an economic resource
        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));
    }
}