use crate::domain::entities::{email, email_attachment};
use serde::Serialize;

/// 邮件列表项（摘要）
#[derive(Debug, Serialize)]
pub struct EmailSummary {
    pub id: i64,
    pub mail_from: String,
    pub sender_name: Option<String>,
    pub subject: Option<String>,
    pub size_bytes: i64,
    pub status: String,
    pub received_at: String,
}

impl From<email::Model> for EmailSummary {
    fn from(m: email::Model) -> Self {
        Self {
            id: m.id,
            mail_from: m.mail_from,
            sender_name: m.sender_name,
            subject: m.subject,
            size_bytes: m.size_bytes,
            status: m.status,
            received_at: m.received_at.format("%Y-%m-%dT%H:%M:%S%.3fZ").to_string(),
        }
    }
}

/// 附件摘要
#[derive(Debug, Serialize)]
pub struct AttachmentSummary {
    pub id: i64,
    pub filename: Option<String>,
    pub content_type: String,
    pub size_bytes: i64,
}

impl From<email_attachment::Model> for AttachmentSummary {
    fn from(a: email_attachment::Model) -> Self {
        Self {
            id: a.id,
            filename: a.filename,
            content_type: a.content_type,
            size_bytes: a.size_bytes,
        }
    }
}

/// 邮件详情
#[derive(Debug, Serialize)]
pub struct EmailDetail {
    pub id: i64,
    pub mail_from: String,
    pub sender_name: Option<String>,
    pub subject: Option<String>,
    pub text_body: Option<String>,
    pub html_body: Option<String>,
    pub size_bytes: i64,
    pub status: String,
    pub received_at: String,
    pub attachments: Vec<AttachmentSummary>,
}
