//! Canonical OHLCV bar type for the ML crate.

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

/// Canonical OHLCV bar representation.
///
/// This is the **single source of truth** for OHLCV bar data across the ML crate.
/// All feature extractors, regime detectors, data loaders, and evaluation code
/// should use this type rather than defining local copies.
///
/// # Fields
/// - `timestamp`: UTC timestamp of the bar
/// - `open`, `high`, `low`, `close`: Price fields (f64)
/// - `volume`: Trade volume (f64)
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct OHLCVBar {
    pub timestamp: DateTime<Utc>,
    pub open: f64,
    pub high: f64,
    pub low: f64,
    pub close: f64,
    pub volume: f64,
}

impl Default for OHLCVBar {
    fn default() -> Self {
        Self {
            // UNIX epoch -- from_timestamp(0, 0) is infallible for these inputs
            timestamp: match DateTime::<Utc>::from_timestamp(0, 0) {
                Some(ts) => ts,
                None => Utc::now(),
            },
            open: 0.0,
            high: 0.0,
            low: 0.0,
            close: 0.0,
            volume: 0.0,
        }
    }
}
