#![deny(clippy::unwrap_used, clippy::expect_used)]
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]

//! Common utilities and shared types for Foxhunt HFT Trading System
//!
//! This crate contains shared utilities that are used across multiple services
//! in the Foxhunt HFT trading system, eliminating code duplication and providing
//! a consistent interface for common operations.
//!
//! # Modules
//!
//! - [`database`] - Database connection utilities and configurations
//! - [`error`] - Common error types and utilities
//! - [`traits`] - Shared traits used across services
//! - [`constants`] - Shared constants and configuration values
//! - [`types`] - Common data types

#![allow(missing_docs)] // Internal implementation details
#![warn(missing_debug_implementations)]
#![allow(clippy::float_arithmetic)] // Financial calculations require float arithmetic
#![warn(rust_2018_idioms)]
#![deny(
    clippy::unwrap_used,
    clippy::expect_used,
    clippy::panic,
    clippy::unimplemented,
    clippy::unreachable
)]

pub mod build_info;
pub mod constants;
pub mod database;
pub mod error;
pub mod model_types;
pub mod features; // Wave D: Shared feature extraction (225 features)
pub mod financial_types;
pub mod market_data;
pub mod metrics; // Wave 5: Prometheus metrics infrastructure (W5-3)
pub mod ml_strategy;
pub mod observability; // Wave 5: Structured logging and observability
pub mod regime_persistence;
pub mod resilience; // Wave 5: Circuit breaker and retry patterns
pub mod thresholds;
pub mod tls;
pub mod traits;
pub mod types;
#[cfg(feature = "questdb")]
pub mod questdb;

// Re-export database types for external use
pub use database::{DatabaseConfig, DatabaseError, DatabasePool};

// Re-export commonly used types at crate root for convenience
pub use types::{
    AccountId, Aggregate, BarEvent, BrokerType, CommonTypeError, ConfigVersion, ConnectionEvent,
    ConnectionInfo, ConnectionStatus, Currency, DataType, ErrorEvent, Execution, GenericTimestamp,
    HftTimestamp, Level2Update, MarketDataEvent, MarketRegime, MarketStatus, Money, Order,
    OrderBookEvent, OrderEvent, OrderEventType, OrderId, OrderSide, OrderStatus, OrderType,
    Position, PositionMap, Price, PriceLevel, Quantity, QuoteEvent, RequestId, ResourceLimits,
    ServiceId, ServiceStatus, Subscription, Symbol, TimeInForce, Timestamp, TradeEvent, TradeId,
    Volume,
};

// Re-export error types
pub use error::{CommonError, CommonResult};

// Re-export model types
pub use model_types::ModelType;

// Re-export common traits for convenience
pub use traits::{
    CircuitBreaker, Configurable, DetailedHealth, GracefulShutdown, HealthCheck, HealthStatus,
    Metrics, RateLimitStatus, RateLimited, Reloadable, Service,
};

// Market data types: use common::market_data::{MarketDataEvent, TradeEvent, QuoteEvent, BarEvent, etc.}
// (Not re-exported at crate root to avoid name collisions with types:: re-exports)
pub mod trading;

// Re-export shared ML strategy types
pub use ml_strategy::{
    MLModelAdapter, MLModelPerformance, MLPrediction,
    SharedMLStrategy,
};

// Re-export canonical financial types (aliased to avoid collision with old types:: re-exports)
// Once migration completes in Phase 6, these become Price/Quantity/Money directly.
pub use financial_types::{
    Money as FinancialMoney,
    Price as FinancialPrice,
    Quantity as FinancialQuantity,
    Ratio,
    SCALE as FINANCIAL_SCALE,
};

// Re-export regime persistence manager
pub use regime_persistence::RegimePersistenceManager;

// Re-export feature extraction types and functions
pub use features::{
    BarData,
    // Technical indicators (streaming + batch)
    RSI, EMA, MACD, BollingerBands, ATR, ADX,
    rsi_batch, ema_batch, macd_batch, bollinger_batch, atr_batch, adx_batch,
};

// Re-export resilience patterns (Wave 5: Error handling and fault tolerance)
pub use resilience::{
    BoundedExecutor,
    BoundedExecutorError,
    CircuitBreakerConfig,
    CircuitBreakerState,
    retry_with_backoff,
    RetryConfig,
    RetryContext,
    RetryError,
};

// Re-export observability infrastructure (Wave 5: Structured logging and observability)
pub use crate::observability::{
    init_observability,
    CorrelationId,
    CorrelationIdExt,
    JsonLoggerConfig,
    LogLevel,
    TracingConfig,
    CORRELATION_ID_HEADER,
};

// Test utilities module (available for all tests)
#[cfg(test)]
pub mod test_utils;

// Test module for database features
#[cfg(all(test, feature = "database"))]
mod sqlx_test;
