use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct LiveDecisionEvent {
#[serde(rename = "type")]
pub r#type: Type,
#[serde(rename = "event_id")]
pub event_id: String,
#[serde(rename = "delegation_id", deserialize_with = "Option::deserialize")]
pub delegation_id: Option<String>,
#[serde(rename = "trigger_id", deserialize_with = "Option::deserialize")]
pub trigger_id: Option<String>,
#[serde(rename = "source_event_type", deserialize_with = "Option::deserialize")]
pub source_event_type: Option<Box<models::LiveDecisionEventSourceEventType>>,
#[serde(rename = "source_event_id", deserialize_with = "Option::deserialize")]
pub source_event_id: Option<String>,
#[serde(rename = "event")]
pub event: Box<models::LiveDecisionCompleted>,
}
impl LiveDecisionEvent {
pub fn new(
r#type: Type,
event_id: String,
delegation_id: Option<String>,
trigger_id: Option<String>,
source_event_type: Option<models::LiveDecisionEventSourceEventType>,
source_event_id: Option<String>,
event: models::LiveDecisionCompleted,
) -> LiveDecisionEvent {
LiveDecisionEvent {
r#type,
event_id,
delegation_id,
trigger_id,
source_event_type: source_event_type.map(Box::new),
source_event_id,
event: Box::new(event),
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
#[serde(rename = "decision.event")]
DecisionEvent,
}
impl Default for Type {
fn default() -> Type {
Self::DecisionEvent
}
}
impl std::fmt::Display for LiveDecisionEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match serde_json::to_string(self) {
Ok(s) => write!(f, "{}", s),
Err(_) => Err(std::fmt::Error),
}
}
}