use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DeliveryState {
Pending,
Delivered,
Acked,
DeadLettered,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeliveryRecord {
pub state: DeliveryState,
pub attempts: u32,
pub updated_at: DateTime<Utc>,
}
impl DeliveryRecord {
pub fn pending() -> Self {
Self {
state: DeliveryState::Pending,
attempts: 0,
updated_at: Utc::now(),
}
}
pub fn mark(&mut self, state: DeliveryState) {
self.state = state;
self.updated_at = Utc::now();
}
}