//! Dirigent ACP API
//!
//! This crate exposes an ACP (Agent-Client Protocol) API for Dirigent,
//! allowing other ACP clients to interact with Dirigent.
//!
//! ## Modules
//!
//! - [`config`] - Server configuration types
//! - [`error`] - Error types and JSON-RPC error conversion
//! - [`event_bridge`] - Event forwarding from source streams to SSE clients
//! - [`jsonrpc`] - JSON-RPC 2.0 request/response types
//! - [`router`] - Axum router and HTTP handlers
//! - [`rpc`] - JSON-RPC request handler and method dispatch
//! - [`session_manager`] - Session mapping and client connection tracking
//! - [`sse`] - SSE notifications for streaming events to clients
//!
//! ## Example
//!
//! ```rust,ignore
//! use dirigent_acp_api::{
//!     AcpServerConfig, NoOpConnectorOperations,
//!     router::{AcpServerState, create_acp_server_router},
//! };
//!
//! // Create server configuration
//! let config = AcpServerConfig::enabled()
//!     .set_port(3001)
//!     .set_max_connections(100);
//!
//! // Create server state
//! let state = AcpServerState::new(config);
//!
//! // Create the router with connector operations
//! let router = create_acp_server_router(state, NoOpConnectorOperations);
//!
//! // Run with axum
//! let listener = tokio::net::TcpListener::bind("0.0.0.0:3001").await?;
//! axum::serve(listener, router).await?;
//! ```

// Modules
pub mod agent_requests;
pub mod config;
pub mod error;
pub mod event_bridge;
pub mod jsonrpc;
pub mod router;
pub mod rpc;
pub mod session_manager;
pub mod sse;

// Re-exports for convenience
pub use agent_requests::AgentRequestTracker;
pub use config::AcpServerConfig;
pub use error::{AcpServerError, JsonRpcErrorObject};
pub use event_bridge::{EventBridge, EventBridgeConfig};
pub use jsonrpc::{
    JsonRpcId, JsonRpcRequest, JsonRpcRequestBatch, JsonRpcResponse, JsonRpcResponseBatch,
    JSONRPC_VERSION,
};
pub use router::{create_acp_server_router, AcpServerState, RouterState};
pub use rpc::{
    ConnectorInfo, ConnectorOperations, NoOpConnectorOperations, RpcHandler, SessionInfo,
    ACP_PROTOCOL_VERSION, SERVER_NAME,
};
pub use session_manager::{ClientConnection, ClientInfo, SessionManager, SessionMapping};
pub use sse::{AcpNotification, SseNotifier, translate_event};

use axum::{response::Json, routing::get, Router};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct ApiInfo {
    pub name: String,
    pub version: String,
    pub description: String,
}

/// Create the ACP API router
pub fn create_api_router() -> Router {
    Router::new()
        .route("/", get(api_info))
        .route("/health", get(health_check))
}

/// Get API information
async fn api_info() -> Json<ApiInfo> {
    Json(ApiInfo {
        name: "dirigent_acp_api".to_string(),
        version: env!("CARGO_PKG_VERSION").to_string(),
        description: "ACP API for Dirigent - orchestrates agentic clients".to_string(),
    })
}

/// Health check endpoint
async fn health_check() -> Json<serde_json::Value> {
    Json(serde_json::json!({
        "status": "healthy",
        "message": "Dirigent ACP API is running"
    }))
}

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

    #[test]
    fn test_api_info() {
        let info = ApiInfo {
            name: "test".to_string(),
            version: "0.1.0".to_string(),
            description: "test description".to_string(),
        };
        assert_eq!(info.name, "test");
    }
}
