email_delivery_status.rs 48 lignes · 1827 octets
use chrono::{DateTime, Utc};
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

/// SeaORM model for the `email_delivery_status` table.
///
/// Tracks the delivery lifecycle of outbound emails (queued, sent, failed, etc.).
#[derive(Clone, Debug, Serialize, Deserialize, DeriveEntityModel)]
#[sea_orm(table_name = "email_delivery_status")]
pub struct Model {
    /// Primary key.
    #[sea_orm(primary_key)]
    pub id: Uuid,
    /// Category of email (e.g. `"verification"`, `"password_reset"`).
    pub email_type: String,
    /// Destination email address.
    pub recipient: String,
    /// Name of the template used to render the email body.
    pub template: String,
    /// Current delivery state (e.g. `"pending"`, `"sent"`, `"failed"`).
    #[sea_orm(indexed)]
    pub state: String,
    /// SMTP response code from the last delivery attempt.
    pub smtp_code: Option<String>,
    /// Full SMTP response message from the last delivery attempt.
    pub smtp_response: Option<String>,
    /// Number of delivery attempts made so far.
    pub attempt_count: i32,
    /// Timestamp of the most recent delivery attempt.
    pub last_attempt_at: Option<DateTime<Utc>>,
    /// Timestamp of the last state transition.
    #[sea_orm(indexed)]
    pub last_state_at: DateTime<Utc>,
    /// Optional correlation ID linking this record to a business transaction.
    pub correlation_id: Option<Uuid>,
    /// Timestamp when this record was created.
    #[sea_orm(indexed)]
    pub created_at: DateTime<Utc>,
    /// Timestamp of the last update to this record.
    pub updated_at: DateTime<Utc>,
}

/// SeaORM relations for the EmailDeliveryStatus entity (none defined).
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}