//! Semantic Triggers module for AiFastDb
//!
//! Provides a flexible trigger system for executing custom logic during
//! database write operations.
//!
//! # Overview
//!
//! The trigger system allows you to hook into the write pipeline at three phases:
//!
//! - **Pre-Write**: Before data is committed (can abort or modify)
//! - **On-Write**: During the write operation (fast, synchronous modifications)
//! - **Post-Write**: After data is committed (side effects, notifications)
//!
//! # Architecture
//!
//! ## Synchronous Pipeline (Default)
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │                     Write Pipeline                          │
//! │                                                             │
//! │  Input ──► Pre-Write ──► On-Write ──► Commit ──► Post-Write │
//! │              │             │                        │       │
//! │              ▼             ▼                        ▼       │
//! │         [Abort?]      [Modify?]              [Side Effects] │
//! │         [Modify?]                           [Notifications] │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! ## Async Pipeline (Recommended for high-throughput)
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │              Async Write Pipeline (Non-blocking)            │
//! │                                                             │
//! │  Input ──► Pre-Write ──► On-Write ──► Commit ────────►[Return]
//! │              │             │              │                  │
//! │              ▼             ▼              ▼                  │
//! │         [Abort?]      [Modify?]    ┌─────────────┐          │
//! │         [Modify?]                  │ Async Queue │          │
//! │                                    └──────┬──────┘          │
//! │                                           ▼                 │
//! │                                    [Worker Tasks]           │
//! │                                    - Post-Write triggers    │
//! │                                    - Deferred actions       │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! # Trigger Types
//!
//! ## Built-in Triggers
//!
//! - `SimilarityTrigger`: Detects potential duplicates
//! - `ImportanceAdjustTrigger`: Auto-adjusts importance scores
//! - `KnowledgeGraphTrigger`: Updates graph relationships
//! - `ConsolidationTrigger`: Triggers memory consolidation
//! - `TimestampValidationTrigger`: Validates timestamps
//!
//! ## Custom Triggers
//!
//! Implement the `RustTrigger` trait to create custom triggers:
//!
//! ```rust,ignore
//! use aifastdb_core::triggers::{RustTrigger, TriggerPhase, TriggerContext, TriggerResult};
//!
//! struct MyTrigger;
//!
//! impl RustTrigger for MyTrigger {
//!     fn id(&self) -> &str { "my-trigger" }
//!     fn name(&self) -> &str { "My Custom Trigger" }
//!     fn phase(&self) -> TriggerPhase { TriggerPhase::PreWrite }
//!     
//!     fn execute(&self, ctx: &TriggerContext) -> TriggerResult {
//!         // Your logic here
//!         TriggerResult::Continue
//!     }
//! }
//! ```
//!
//! # Usage
//!
//! ```rust,ignore
//! use aifastdb_core::triggers::{TriggerRegistry, SimilarityTrigger};
//! use std::sync::Arc;
//!
//! let registry = TriggerRegistry::new();
//!
//! // Register a built-in trigger
//! let trigger = Arc::new(SimilarityTrigger::new(0.9));
//! registry.register(trigger)?;
//!
//! // Execute the write pipeline
//! let (final_node, deferred) = registry.execute_write_pipeline(node, neighbors)?;
//!
//! // Handle deferred actions
//! for action in deferred {
//!     // Process action...
//! }
//! ```

pub mod types;
pub mod registry;
pub mod builtin;
pub mod async_executor;

// Re-export main types
pub use types::{
    TriggerPhase,
    TriggerContext,
    TriggerResult,
    TriggerConfig,
    TriggerPriority,
    TriggerError,
    DeferredAction,
    NeighborInfo,
};

pub use registry::{TriggerRegistry, RustTrigger};

pub use builtin::{
    SimilarityTrigger,
    ImportanceAdjustTrigger,
    KnowledgeGraphTrigger,
    ConsolidationTrigger,
    TimestampValidationTrigger,
    create_default_registry,
};

// Re-export async executor types
pub use async_executor::{
    AsyncTriggerExecutor,
    AsyncTriggerConfig,
    AsyncTriggerMetrics,
    AsyncTriggerError,
    TriggerRequest,
    start_async_trigger_workers,
};
