#![forbid(unsafe_code)]
#![warn(
    missing_docs,
    missing_debug_implementations,
    rust_2018_idioms,
    unreachable_pub
)]

//! # VAPORA Lifecycle Adapter
//!
//! This crate provides integration between syntaxis and VAPORA.
//!
//! Features:
//! - Document lifecycle integration via GraphQL
//! - Multi-agent orchestration
//! - Multi-IA router support (Claude, OpenAI, Gemini, Ollama)
//! - Real-time event streaming
//! - Distributed tracing with OpenTelemetry
//! - mTLS security

pub use syntaxis_core::*;

pub mod agent_bridge;
pub mod doc_lifecycle;
pub mod event_stream;
pub mod llm_provider;
pub mod multi_ia_router;
pub mod nats_bridge;
pub mod observability;
pub mod orchestration;
pub mod plugin;
pub mod security;

#[cfg(feature = "kogral")]
pub mod kogral_bridge;

/// VAPORA lifecycle integration result type
pub type VaporaResult<T> = anyhow::Result<T>;

/// VAPORA configuration
#[derive(Debug, Clone)]
pub struct VaporaConfig {
    /// Doc-lifecycle API endpoint
    pub doc_lifecycle_url: String,
    /// VAPORA API endpoint
    pub vapora_api_url: String,
    /// Enable distributed tracing
    pub enable_tracing: bool,
    /// Enable mTLS
    pub enable_mtls: bool,
    /// Certificate path for mTLS
    pub cert_path: Option<String>,
    /// Private key path for mTLS
    pub key_path: Option<String>,
}

impl Default for VaporaConfig {
    fn default() -> Self {
        Self {
            doc_lifecycle_url: "http://localhost:7000".to_string(),
            vapora_api_url: "http://localhost:8000".to_string(),
            enable_tracing: true,
            enable_mtls: false,
            cert_path: None,
            key_path: None,
        }
    }
}

/// Initialize VAPORA lifecycle adapter
pub async fn init(config: VaporaConfig) -> VaporaResult<()> {
    // Initialize observability if enabled
    if config.enable_tracing {
        observability::init_tracing()?;
    }

    // Initialize security if enabled
    if config.enable_mtls {
        security::init_mtls(&config).await?;
    }

    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_vapora_config_default() {
        let config = VaporaConfig::default();
        assert_eq!(config.doc_lifecycle_url, "http://localhost:7000");
        assert_eq!(config.vapora_api_url, "http://localhost:8000");
        assert!(config.enable_tracing);
        assert!(!config.enable_mtls);
    }
}
