//! Adaptive rate limiter that detects rate-limiting signals and backs off per host.
//!
//! This module provides the [`AdaptiveRateLimiter`] type which tracks per-host
//! response patterns and automatically adjusts request rates to avoid triggering
//! rate limits or blocks.

/// Defines the backoff and rate limiter abstractions.
pub mod backoff;

/// Tracks internal state and response history per host.
pub mod host_state;

/// Provides the core adaptive rate limiting logic.
pub mod limiter;

pub use backoff::{BackoffStatus, SyncRateLimiter};
pub use limiter::AdaptiveRateLimiter;

use std::time::Duration;

/// Default base backoff duration when rate limiting is detected.
#[doc(hidden)]
pub const DEFAULT_BACKOFF: Duration = Duration::from_millis(250);

/// Maximum backoff duration to prevent excessive delays.
#[doc(hidden)]
pub const MAX_BACKOFF: Duration = Duration::from_secs(60);

/// Window size for tracking recent response times for spike detection.
pub(crate) const LATENCY_WINDOW_SIZE: usize = 10;

/// Threshold multiplier for detecting response time spikes.
pub(crate) const LATENCY_SPIKE_THRESHOLD: f64 = 3.0;

/// Minimum number of samples before considering latency spike detection.
pub(crate) const MIN_SAMPLES_FOR_SPIKE: usize = 3;

/// Threshold for error rate (403/503) to trigger backoff.
pub(crate) const ERROR_RATE_THRESHOLD: f64 = 0.5;

/// Minimum number of requests before checking error rates.
pub(crate) const MIN_REQUESTS_FOR_ERROR_RATE: usize = 5;
