//! Host-side mirrors of cuda/lob_state.cuh layouts.
//! See spec §2 (CUDA data layout) and §5b (state ownership).

pub const BOOK_LEVELS: usize = 10;
pub const N_HORIZONS: usize = 5;
pub const MAX_LIMITS: usize = 32;
pub const MAX_STOPS: usize = 16;
/// Bytes per LimitSlot — matches cuda/lob_state.cuh::LimitSlot.
pub const LIMIT_SLOT_BYTES: usize = 32;
/// Bytes per StopSlot — matches cuda/lob_state.cuh::StopSlot.
pub const STOP_SLOT_BYTES: usize = 32;
/// Bytes per Orders struct (limits[32] + stops[16]).
pub const ORDERS_BYTES: usize = MAX_LIMITS * LIMIT_SLOT_BYTES + MAX_STOPS * STOP_SLOT_BYTES;
/// Max closed-trade records buffered per backtest before the host
/// must drain. Sized for a single fixture day at ~30s decision cadence.
pub const TRADE_LOG_CAP: usize = 1024;
/// Bytes per TradeRecord (must match crates/ml-backtesting/src/order.rs).
pub const TRADE_RECORD_BYTES: usize = 40;
/// Bytes per OpenTradeState (kernel-side tracking of currently-open entry).
pub const OPEN_TRADE_STATE_BYTES: usize = 24;
/// Bytes per OrderEvent (must match crates/ml-backtesting/src/order.rs).
pub const ORDER_EVENT_BYTES: usize = 24;
/// Max OrderEvent records buffered per backtest in the audit ring.
pub const RING_CAP_EVENTS: usize = 256;

/// Flat host-side mirror of `cuda/lob_state.cuh::Book`.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct BookFlat {
    pub bid_px: [f32; BOOK_LEVELS],
    pub bid_sz: [f32; BOOK_LEVELS],
    pub ask_px: [f32; BOOK_LEVELS],
    pub ask_sz: [f32; BOOK_LEVELS],
}

/// Host-side mirror of `cuda/lob_state.cuh::Pos`. Pod for direct
/// host↔device transfer. Field order MUST match the cuda struct.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
pub struct PosFlat {
    pub position_lots: i32,
    pub vwap_entry: f32,
    pub realized_pnl: f32,
    pub peak_equity: f32,
    pub submission_overflow: u32,
    pub open_horizon_mask: u32,
}

/// Host-side mirror of `cuda/lob_state.cuh::LimitSlot` (28 bytes).
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
pub struct LimitSlotFlat {
    pub active: u8,
    pub side: u8,
    pub kind: u8,
    pub oco_pair: u8,
    pub price: f32,
    pub size_remaining: f32,
    pub queue_position: f32,
    pub arrival_ts_ns: u64,
    pub gen_counter: u16,
    pub _pad: [u8; 6],
}

/// Host-side mirror of `cuda/lob_state.cuh::StopSlot` (28 bytes).
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
pub struct StopSlotFlat {
    pub active: u8,
    pub side: u8,
    pub kind: u8,
    pub oco_pair: u8,
    pub trigger_price: f32,
    pub limit_price: f32,
    pub size: f32,
    pub arrival_ts_ns: u64,
    pub gen_counter: u16,
    pub _pad: [u8; 6],
}

