//! Documenter agent integration with doc-lifecycle

use crate::config::PluginConfig;
use crate::plugin::DocLifecyclePlugin;
use crate::Result;

/// Documenter agent integration
#[derive(Debug)]
pub struct DocumenterIntegration {
    plugin: DocLifecyclePlugin,
    config: PluginConfig,
}

impl DocumenterIntegration {
    /// Create a new documenter integration
    pub fn new(config: PluginConfig) -> Result<Self> {
        let plugin = DocLifecyclePlugin::new(config.clone())?;

        Ok(Self { plugin, config })
    }

    /// Handle task completion event
    pub async fn on_task_completed(&mut self, task_id: &str) -> Result<()> {
        tracing::info!(
            "Documenter: Processing task completion for task {}",
            task_id
        );

        // 1. Process documentation
        self.plugin.process_task_docs(task_id).await?;

        // 2. Update root files (README, CHANGELOG, ROADMAP)
        self.update_root_files(task_id).await?;

        // 3. Publish event for other agents
        self.publish_docs_updated_event(task_id).await?;

        Ok(())
    }

    async fn update_root_files(&self, _task_id: &str) -> Result<()> {
        // TODO: Update README, CHANGELOG, ROADMAP
        Ok(())
    }

    async fn publish_docs_updated_event(&self, _task_id: &str) -> Result<()> {
        // TODO: Publish to NATS
        Ok(())
    }

    /// Get current configuration
    #[must_use]
    pub fn config(&self) -> &PluginConfig {
        &self.config
    }
}
