#![allow(clippy::mod_module_files)] // Complex module structure is more maintainable than single file
//! Trading Engine Internal Types
//!
//! This module provides internal types specific to the trading engine.
//! For common types, use the `common` crate instead.
//!
//! # Internal Trading Engine Types
//! - **Basic Types**: Trading engine specific primitives
//! - **Metrics**: Trading engine performance metrics
//! - **Type Registry**: Engine-specific type management

// Note: #![warn(missing_docs)] temporarily disabled to focus on critical clippy fixes
// Will be re-enabled once comprehensive documentation pass is completed
#![deny(
    clippy::unwrap_used,
    clippy::expect_used,
    clippy::panic,
    clippy::unimplemented,
    clippy::unreachable
)]
#![warn(clippy::perf, clippy::correctness)]
#![warn(missing_debug_implementations)]
#![warn(rust_2018_idioms)]
// Allow HFT performance optimizations and patterns that clippy warns about
// These are necessary for sub-50μs latency requirements
#![allow(
    clippy::cast_possible_truncation,
    clippy::cast_precision_loss,
    clippy::cast_sign_loss,
    clippy::cast_possible_wrap,
    clippy::arithmetic_side_effects,
    clippy::float_arithmetic,
    clippy::integer_division,
    clippy::missing_docs_in_private_items,
    clippy::doc_markdown,
    clippy::indexing_slicing,                  // Safe with bounds checks in hot paths
    clippy::as_conversions,                    // Necessary for u64<->i64 timestamp conversions
    clippy::default_numeric_fallback,          // Type inference is clear in context
    clippy::type_complexity,                   // Some complex types unavoidable for performance
    clippy::missing_errors_doc,                // Internal APIs don't need full error documentation
    clippy::similar_names,                     // bid/ask, buy/sell are domain concepts
    clippy::module_name_repetitions,           // trading_engine::types::TradingType is clear
    clippy::too_many_lines,                    // Large modules necessary for inlining
    clippy::struct_excessive_bools,            // Boolean flags efficient for HFT state
    clippy::too_many_arguments,                // Some functions need many parameters for performance
    clippy::cast_lossless,                     // as casts are intentional for HFT performance
    clippy::inline_always,                     // Explicit #[inline(always)] is performance-critical
    clippy::multiple_unsafe_ops_per_block,     // RDTSC requires multiple unsafe ops
    clippy::option_if_let_else,                // Match is often more readable in hot paths
    clippy::unsafe_derive_deserialize,         // Hardware timestamp needs unsafe + serde
    clippy::match_same_arms,                   // Explicit match arms preferred for clarity (fixed selectively)
    clippy::shadow_reuse,                      // Variable reuse is intentional in hot paths
    clippy::shadow_unrelated,                  // Shadow patterns are intentional
    clippy::clone_on_ref_ptr,                  // Arc::clone is intentional for shared state
    clippy::modulo_arithmetic,                 // Modulo is used safely for financial calculations
    clippy::map_err_ignore,                    // Error conversion doesn't need original context
    clippy::manual_range_contains,             // Explicit conditions clearer in some cases
    clippy::manual_let_else,                   // if-let pattern preferred for error handling
    clippy::missing_const_for_fn,              // Const fn not critical for performance
    clippy::str_to_string                      // Fixed where found
)]

// ============================================================================
// TRADING ENGINE INTERNAL TYPE MODULES
// ============================================================================

// NOTE: basic module commented out to prevent conflicts with lib.rs exports
// All basic types are available from crate root via lib.rs
// pub mod basic;

/// Trading engine specific timestamp utilities
pub mod timestamp_utils;

/// Trading engine performance metrics
pub mod metrics;

/// Trading engine type registry for dynamic type management
pub mod type_registry;

/// Trading engine error types
pub mod errors;

/// Trading engine events module
pub mod events;

/// Trading engine financial types
pub mod financial;

/// Trading engine validation utilities
pub mod validation;

/// Metrics cardinality limiter for Prometheus optimization
pub mod cardinality_limiter;

/// Circuit breaker for fault tolerance
pub mod circuit_breaker;

/// Optimized order book implementation
pub mod optimized_order_book;

/// Test utilities for standardized test configuration
#[cfg(test)]
pub mod test_utils;

// REMOVED: Prelude module - no more convenience re-exports

// REMOVED: Service prelude - eliminated anti-pattern, use common::* instead

// ============================================================================
// TRADING ENGINE INTERNAL ERROR TYPES
// ============================================================================

use serde::{Deserialize, Serialize};
use thiserror::Error;

/// Trading engine specific errors
#[derive(Error, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
/// TradingEngineError
///
/// Auto-generated documentation placeholder - enhance with specifics
pub enum TradingEngineError {
    /// Engine initialization failed
    #[error("Engine initialization failed: {0}")]
    // InitializationFailed variant
    InitializationFailed(String),
    /// Engine state invalid
    #[error("Invalid engine state: {0}")]
    // InvalidState variant
    InvalidState(String),
    /// Engine execution error
    #[error("Engine execution error: {0}")]
    // ExecutionError variant
    ExecutionError(String),
}

// ============================================================================
// TRADING ENGINE INTERNAL RE-EXPORTS
// ============================================================================

// NOTE: basic::* not re-exported to prevent conflicts with lib.rs
// All basic types are available from crate root via lib.rs

// NOTE: NO MORE RE-EXPORTS - All types must be imported directly at usage sites
// This enforces proper dependency management and prevents circular imports

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

    #[test]
    fn test_trading_engine_error_variants() {
        let init_error = TradingEngineError::InitializationFailed("Failed to init".to_string());
        let state_error = TradingEngineError::InvalidState("Bad state".to_string());
        let exec_error = TradingEngineError::ExecutionError("Execution failed".to_string());

        assert_eq!(
            format!("{}", init_error),
            "Engine initialization failed: Failed to init"
        );
        assert_eq!(
            format!("{}", state_error),
            "Invalid engine state: Bad state"
        );
        assert_eq!(
            format!("{}", exec_error),
            "Engine execution error: Execution failed"
        );
    }
}
