use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::deactivation_reason::DeactivationReason;
use crate::passport::PassportId;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EolEvent {
pub passport_id: PassportId,
pub reason: DeactivationReason,
pub declared_by: String,
pub declared_at: DateTime<Utc>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub material_recovery: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
}
impl EolEvent {
#[must_use]
pub fn new(
passport_id: PassportId,
reason: DeactivationReason,
declared_by: impl Into<String>,
) -> Self {
Self {
passport_id,
reason,
declared_by: declared_by.into(),
declared_at: Utc::now(),
material_recovery: None,
notes: None,
}
}
#[must_use]
pub fn requires_derogation(&self) -> bool {
matches!(self.reason, DeactivationReason::Destroyed { .. })
}
}