use std::{
any::Any,
fmt::{Debug, Display},
};
use indexmap::IndexMap;
use nautilus_core::{UUID4, UnixNanos};
use nautilus_model::identifiers::TraderId;
use serde::{Deserialize, Serialize};
use ustr::Ustr;
use crate::enums::ComponentState;
#[repr(C)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type")]
#[cfg_attr(
feature = "python",
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model", from_py_object)
)]
pub struct ComponentStateChanged {
pub trader_id: TraderId,
pub component_id: Ustr,
pub component_type: Ustr,
pub state: ComponentState,
pub config: IndexMap<String, String>,
pub event_id: UUID4,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
impl ComponentStateChanged {
#[expect(clippy::too_many_arguments)]
#[must_use]
pub fn new(
trader_id: TraderId,
component_id: Ustr,
component_type: Ustr,
state: ComponentState,
config: IndexMap<String, String>,
event_id: UUID4,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Self {
Self {
trader_id,
component_id,
component_type,
state,
config,
event_id,
ts_event,
ts_init,
}
}
pub fn as_any(&self) -> &dyn Any {
self
}
}
impl Display for ComponentStateChanged {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}(trader_id={}, component_id={}, component_type={}, state={}, event_id={})",
stringify!(ComponentStateChanged),
self.trader_id,
self.component_id,
self.component_type,
self.state,
self.event_id,
)
}
}