use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum EnvelopePayload {
    TaskDelegation { description: String },
    ProgressUpdate { pct: u8, message: String },
    ResultShare { content: String },
    KnowledgePush { key: String, value: String },
    Interrupt { reason: String },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Priority {
    Low,
    Normal,
    High,
    Critical,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Envelope {
    pub id: Uuid,
    pub from: String,
    pub to: Option<String>,
    pub channel: String,
    pub payload: EnvelopePayload,
    pub priority: Priority,
    pub created_at: DateTime<Utc>,
}

impl Envelope {
    pub fn new(from: impl Into<String>, payload: EnvelopePayload) -> Self {
        Self {
            id: Uuid::new_v4(),
            from: from.into(),
            to: None,
            channel: "default".into(),
            payload,
            priority: Priority::Normal,
            created_at: Utc::now(),
        }
    }
}
