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

//! # VAPORA Tracking Adapter
//!
//! Integration adapter for `tracking-core` library with VAPORA-specific
//! features.
//!
//! This crate re-exports the standalone `tracking-core` library and adds:
//! - VAPORA agent integration
//! - NATS event streaming (optional)
//! - Task workflow integration
//! - Multi-tenant tracking support
//!
//! ## Example
//!
//! ```ignore
//! use vapora_tracking::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     // Initialize database
//!     let db = TrackingDb::new("sqlite://tracking.db").await?;
//!
//!     // Create a tracking entry
//!     let entry = TrackingEntry::new(
//!         "/path/to/project",
//!         TrackingSource::CoderChanges,
//!         "Fixed authentication bug".to_string(),
//!     );
//!
//!     // Store it
//!     db.insert_entry(&entry).await?;
//!
//!     Ok(())
//! }
//! ```

// Re-export core tracking types and functionality
pub use tracking_core::*;

/// VAPORA-specific plugin integration
pub mod plugin {
    use tracking_core::TrackingDb;

    /// Plugin for integrating tracking with VAPORA agents
    #[derive(Debug, Clone)]
    pub struct TrackingPlugin {
        /// Database instance
        pub db: std::sync::Arc<TrackingDb>,
    }

    impl TrackingPlugin {
        /// Create a new tracking plugin
        pub async fn new(db_url: &str) -> tracking_core::Result<Self> {
            Ok(Self {
                db: std::sync::Arc::new(TrackingDb::new(db_url).await?),
            })
        }

        /// Called when a task is completed
        pub async fn on_task_completed(&self, task_id: &str) -> tracking_core::Result<()> {
            tracing::info!("Task completed: {}", task_id);
            // TODO: Implement task completion tracking
            Ok(())
        }

        /// Called when a document is created
        pub async fn on_document_created(&self, doc_path: &str) -> tracking_core::Result<()> {
            tracing::info!("Document created: {}", doc_path);
            // TODO: Implement document tracking
            Ok(())
        }
    }
}

/// NATS event streaming integration (optional)
#[cfg(feature = "nats")]
pub mod events {
    use crate::TrackingEntry;

    /// Event published when a tracking entry is created
    #[derive(Debug, Clone)]
    pub struct TrackingEntryCreatedEvent {
        /// The entry that was created
        pub entry: TrackingEntry,
    }

    // TODO: Implement NATS publisher
}

pub mod prelude {
    //! Prelude for common imports
    pub use tracking_core::{
        EntryType, Estimate, Impact, Priority, Result, TodoStatus, TrackingDb, TrackingEntry,
        TrackingError, TrackingSource,
    };

    pub use crate::plugin::TrackingPlugin;
}

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

    #[test]
    fn test_adapter_exports() {
        // Verify tracking-core types are accessible
        let _source = TrackingSource::CoderChanges;
        let _impact = Impact::Backend;
        let _priority = Priority::High;
    }
}
