//! Named constants for the `LastID` SDK.
//!
//! This module centralizes all magic numbers and configuration defaults
//! to improve code readability and maintainability (FR-014).

// =============================================================================
// TIMEOUT CONSTANTS
// =============================================================================

/// Default HTTP request timeout in seconds.
///
/// Used as the default value for `SDKConfig.timeout_seconds`.
pub const DEFAULT_TIMEOUT_SECONDS: u64 = 30;

/// Default TCP connection timeout in seconds.
///
/// Time allowed for establishing a TCP connection to the server.
pub const DEFAULT_CONNECT_TIMEOUT_SECONDS: u64 = 10;

/// Default response read timeout in seconds.
///
/// Time allowed for reading the HTTP response body after headers are received.
pub const DEFAULT_READ_TIMEOUT_SECONDS: u64 = 30;

// =============================================================================
// RETRY CONSTANTS
// =============================================================================

/// Default retry-after duration in seconds when server doesn't specify.
///
/// Used when a 429/503 response lacks a `Retry-After` header.
pub const DEFAULT_RETRY_AFTER_SECONDS: u64 = 60;

// =============================================================================
// CACHE CONSTANTS
// =============================================================================

/// Default cache TTL in seconds.
///
/// How long trust registry entries are cached before refresh.
pub const DEFAULT_CACHE_TTL_SECONDS: u64 = 60;

// =============================================================================
// POLLING CONSTANTS
// =============================================================================

/// Default maximum polling duration in seconds.
///
/// Maximum time to wait for credential request completion.
pub const DEFAULT_POLLING_MAX_DURATION_SECONDS: u64 = 300;

// =============================================================================
// CLOCK CONSTANTS
// =============================================================================

/// Default clock skew tolerance in seconds.
///
/// Maximum allowed difference between local and server clocks
/// when validating credential timestamps (exp, nbf claims).
pub const DEFAULT_CLOCK_SKEW_SECONDS: u64 = 60;

// =============================================================================
// DPOP CONSTANTS
// =============================================================================

/// `DPoP` proof maximum lifetime in seconds (RFC 9449).
///
/// `DPoP` proofs should not be valid for more than 5 minutes
/// to limit replay attack windows.
pub const DPOP_PROOF_MAX_LIFETIME_SECONDS: u64 = 300;

// =============================================================================
// CONNECTION POOL CONSTANTS
// =============================================================================

/// Default connection pool idle timeout in seconds.
///
/// How long idle connections are kept in the pool before being closed.
pub const DEFAULT_POOL_IDLE_TIMEOUT_SECONDS: u64 = 30;

/// Default maximum idle connections per host.
///
/// Maximum number of idle connections kept open to each host.
pub const DEFAULT_POOL_MAX_IDLE_PER_HOST: usize = 5;

// =============================================================================
// WEBSOCKET CONSTANTS
// =============================================================================

/// Default WebSocket connect timeout in seconds.
pub const DEFAULT_WEBSOCKET_CONNECT_TIMEOUT_SECONDS: u64 = 10;

/// Default WebSocket receive timeout in seconds.
///
/// Maximum time to wait for a message after connection is established.
pub const DEFAULT_WEBSOCKET_RECEIVE_TIMEOUT_SECONDS: u64 = 300;

// =============================================================================
// CORRELATION ID CONSTANTS
// =============================================================================

/// Default correlation ID header name.
///
/// Header name used for request tracing across services.
pub const DEFAULT_CORRELATION_ID_HEADER: &str = "X-Request-ID";

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

    #[test]
    fn test_constants_are_reasonable() {
        // Verify constants have sensible values
        assert!(DEFAULT_TIMEOUT_SECONDS > 0);
        assert!(DEFAULT_TIMEOUT_SECONDS <= 300);

        assert!(DEFAULT_CONNECT_TIMEOUT_SECONDS > 0);
        assert!(DEFAULT_CONNECT_TIMEOUT_SECONDS <= DEFAULT_TIMEOUT_SECONDS);

        assert!(DEFAULT_CLOCK_SKEW_SECONDS > 0);
        assert!(DEFAULT_CLOCK_SKEW_SECONDS <= 300);

        assert!(DPOP_PROOF_MAX_LIFETIME_SECONDS > 0);
        assert!(DPOP_PROOF_MAX_LIFETIME_SECONDS <= 600);

        assert!(DEFAULT_POOL_MAX_IDLE_PER_HOST > 0);
        assert!(DEFAULT_POOL_MAX_IDLE_PER_HOST <= 100);
    }

    #[test]
    fn test_correlation_header_is_valid() {
        // Header name should be non-empty and valid HTTP header format
        assert!(!DEFAULT_CORRELATION_ID_HEADER.is_empty());
        assert!(
            DEFAULT_CORRELATION_ID_HEADER
                .chars()
                .all(|c| c.is_ascii_alphanumeric() || c == '-')
        );
    }
}
