use serde_json::json;
use uuid::Uuid;
use crate::context::RumContextSnapshot;
use crate::time;
#[derive(Clone, Debug)]
pub(crate) struct ViewEvent {
pub context: RumContextSnapshot,
pub event_id: String,
pub timestamp: i64,
pub loading_type: String,
}
impl ViewEvent {
pub fn initial(context: RumContextSnapshot) -> Self {
Self {
context,
event_id: Uuid::new_v4().simple().to_string(),
timestamp: time::unix_millis(std::time::SystemTime::now()),
loading_type: "initial_load".to_string(),
}
}
pub fn to_json(&self) -> serde_json::Value {
json!({
"timestamp": self.timestamp,
"event_id": self.event_id,
"event_type": "view",
"type": "pv",
"loading_type": self.loading_type,
})
}
}