//! Streaming ZigZag indicator for swing structure detection on open deviation bars.
//!
//! Identifies swing highs and swing lows — the foundation for trend classification,
//! pattern recognition, and regime labeling in algorithmic trading.
//!
//! ## Key Properties
//!
//! - **No repainting**: Once confirmed, pivots never change price or index.
//! - **Streaming**: Processes one bar at a time with O(1) state.
//! - **Range-bar native**: Threshold τ = N × δ scales naturally with bar width.
//! - **Classification**: Automatic EL/HL/LL base class assignment per segment.
//!
//! ## Quick Start
//!
//! ```
//! use qta::zigzag::{ZigZagConfig, ZigZagState, BarInput};
//!
//! let config = ZigZagConfig::new(3.0, 1.0, 250).unwrap();
//! let mut state = ZigZagState::new(config);
//!
//! let bar = BarInput {
//!     index: 0, timestamp_us: 1_000_000,
//!     high: 5_012_500_000_000, low: 5_000_000_000_000,
//!     close: 5_006_000_000_000, duration_us: Some(60_000_000),
//! };
//! let output = state.process_bar(&bar);
//!
//! if let Some(pivot) = output.newly_confirmed {
//!     println!("Confirmed {} at price {}", pivot.kind, pivot.price);
//! }
//! if let Some(segment) = &output.completed_segment {
//!     println!("Segment: {} (z={:.3})", segment.base_class, segment.z);
//! }
//! ```

pub mod base_class;
pub mod config;
pub mod ctrends;
pub(crate) mod direction;
pub mod segment;
pub mod state;
pub mod types;

pub use config::{ThresholdMode, ZigZagConfig};
pub use ctrends::{CTrendsConfig, filter_ctrends, is_noise_counter_move};
pub use segment::SegmentStats;
pub use state::ZigZagState;
pub use base_class::{classify_high_class, compute_z_high};
pub use types::{BarInput, BaseClass, ConfirmationStatus, Formation, HighClass, Pivot, PivotKind, Segment, ZigZagOutput};

/// Errors from the ZigZag indicator.
#[derive(Debug, Clone, thiserror::Error)]
pub enum ZigZagError {
    #[error("invalid configuration: {0}")]
    InvalidConfig(&'static str),
}
