//! Typed messages flowing through the trading pipeline.

use serde::{Deserialize, Serialize};

/// Signal from ML model prediction.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PredictionSignal {
    /// Trading symbol (e.g. "EURUSD").
    pub symbol: String,
    /// Predicted direction.
    pub direction: SignalDirection,
    /// Confidence score from the model (0.0 to 1.0).
    pub confidence: f64,
    /// Identifier of the model that produced the signal.
    pub model_id: String,
}

/// Direction of a trading signal.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SignalDirection {
    /// Go long (buy).
    Long,
    /// Go short (sell).
    Short,
    /// No position / flat.
    Flat,
}

/// Sized order ready for execution.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SizedOrder {
    /// Trading symbol.
    pub symbol: String,
    /// Order direction.
    pub direction: SignalDirection,
    /// Position size (quantity of contracts/shares/lots).
    pub quantity: f64,
    /// Confidence carried from the prediction.
    pub confidence: f64,
    /// Model that originated the signal.
    pub model_id: String,
}

/// Risk check result attached to an order.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RiskCheckedOrder {
    /// The sized order that was checked.
    pub order: SizedOrder,
    /// Whether the risk gate approved the order.
    pub risk_approved: bool,
    /// Reason for rejection, if any.
    pub rejection_reason: Option<String>,
}

/// Messages flowing through the pipeline stages.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PipelineMessage {
    /// Raw prediction from ML model.
    Prediction(PredictionSignal),
    /// Order with position size computed.
    Sized(SizedOrder),
    /// Order after risk gate check.
    RiskChecked(RiskCheckedOrder),
    /// Pipeline terminated (no further processing).
    Rejected {
        /// Why the message was rejected.
        reason: String,
        /// Symbol from the original signal.
        original_symbol: String,
    },
}
