//! # photon-etcd-cluster
//!
//! A lightweight cluster coordination library providing leader election
//! and node registry via etcd.
//!
//! ## Main Components
//!
//! - [`ClusterNode`]: Joins cluster, participates in elections
//! - [`ServiceDiscovery`]: Watches cluster state with reactive event streams
//! - [`ClusterEvent`]: Events emitted on cluster changes
//! - [`Node`]: Node metadata (id, ip, last_seen)
//!
//! ## Usage Patterns
//!
//! ### Event-driven (recommended)
//!
//! React to cluster changes as they happen:
//!
//! ```ignore
//! use photon_etcd_cluster::{ServiceDiscovery, ClusterEvent};
//!
//! let discovery = ServiceDiscovery::new(endpoints, "my-service".into());
//! tokio::spawn(async move { discovery.run(None).await });
//!
//! let mut events = discovery.subscribe();
//! while let Ok(event) = events.recv().await {
//!     match event {
//!         ClusterEvent::NodeJoined(n) => update_backends(),
//!         ClusterEvent::LeaderElected(n) => route_writes_to(n),
//!         _ => {}
//!     }
//! }
//! ```
//!
//! ### Watch-based (for metrics/state observation)
//!
//! Efficiently observe state changes without polling:
//!
//! ```ignore
//! let mut watch = discovery.watch_nodes();
//! loop {
//!     watch.changed().await?;
//!     BACKEND_COUNT.set(watch.borrow().len() as i64);
//! }
//! ```
//!
//! ### Direct access (for one-off queries)
//!
//! ```ignore
//! let nodes = discovery.nodes();
//! let leader = discovery.leader();
//! ```
//!
//! ## ClusterNode Example
//!
//! ```ignore
//! use photon_etcd_cluster::ClusterNode;
//! use tokio::sync::broadcast;
//!
//! let node = ClusterNode::new(
//!     vec!["http://localhost:2379".into()],
//!     "node-1".into(),
//!     "127.0.0.1".parse().unwrap(),
//!     "my-service".into(),
//!     Some(5),
//! );
//!
//! let (shutdown_tx, _) = broadcast::channel(1);
//! let mut rx = shutdown_tx.subscribe();
//! node.run(&mut rx).await?;
//!
//! if node.is_leader() {
//!     // Perform leader-only tasks
//! }
//! ```

pub(crate) mod connection;
pub mod cluster_node;
pub mod discovery;
pub mod error;
pub mod event;
pub mod metrics;
pub mod types;

// Re-exports for convenience
pub use cluster_node::{ClusterNode, ClusterNodeBuilder};
pub use discovery::ServiceDiscovery;
pub use error::ClusterError;
pub use event::ClusterEvent;
pub use metrics::{MetricsCollector, NoopMetricsCollector};
#[cfg(feature = "system-metrics")]
pub use metrics::SystemMetricsCollector;
pub use types::{metadata_keys, HealthStatus, Node, NodeMetadata};
