//! Type aliases for complex shared types
//!
//! Common type aliases used throughout the Foxhunt HFT trading system.

use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use std::collections::HashMap;
use std::sync::{Arc, Mutex, RwLock};

// =============================================================================
// Type Aliases for Complex Types
// =============================================================================

/// Common error type for async operations
pub type AsyncResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;

/// Thread-safe hash map for shared state
pub type SharedHashMap<K, V> = Arc<RwLock<HashMap<K, V>>>;

/// Thread-safe hash map with Mutex for shared state
pub type MutexHashMap<K, V> = Arc<Mutex<HashMap<K, V>>>;

/// Thread-safe container for any value
pub type SharedValue<T> = Arc<RwLock<T>>;

/// Thread-safe container with Mutex for any value
pub type MutexValue<T> = Arc<Mutex<T>>;

// Trading-specific type aliases
/// Map of positions by symbol
pub type PositionMap<T> = SharedHashMap<String, T>;

/// Map of orders by order ID
pub type OrderMap<T> = SharedHashMap<String, T>;

/// Map of accounts by account ID
pub type AccountMap<T> = SharedHashMap<String, T>;

/// Map of instruments by instrument ID
pub type InstrumentMap<T> = SharedHashMap<String, T>;

/// Map of market data by symbol
pub type MarketDataMap<T> = SharedHashMap<String, T>;

/// Cache entry with timestamp
pub type CacheEntry<T> = (T, DateTime<Utc>);

/// Cache map with timestamped entries
pub type CacheMap<K, V> = SharedHashMap<K, CacheEntry<V>>;

/// Risk factor loadings by instrument
pub type RiskFactorMap = SharedHashMap<String, HashMap<String, Decimal>>;

/// Performance metrics history
pub type PerformanceHistory<T> = SharedHashMap<String, std::collections::VecDeque<T>>;

/// Model registry for ML models
pub type ModelRegistry<T> = SharedHashMap<String, T>;

/// Generic configuration cache
pub type ConfigCache<K, V> = SharedHashMap<K, V>;
