use crate::domain::entities::mailbox;
use serde::Serialize;

/// 邮箱视图
#[derive(Debug, Serialize)]
pub struct MailboxVO {
    pub id: i64,
    pub address: String,
    pub local_part: String,
    pub domain: String,
    pub note: Option<String>,
    pub status: String,
    pub max_quota_bytes: i64,
    pub used_bytes: i64,
    pub expires_at: String,
    pub created_at: String,
}

impl From<mailbox::Model> for MailboxVO {
    fn from(m: mailbox::Model) -> Self {
        Self {
            id: m.id,
            address: m.address,
            local_part: m.local_part,
            domain: m.domain,
            note: m.note,
            status: m.status,
            max_quota_bytes: m.max_quota_bytes,
            used_bytes: m.used_bytes,
            expires_at: m.expires_at.format("%Y-%m-%dT%H:%M:%S%.3fZ").to_string(),
            created_at: m.created_at.format("%Y-%m-%dT%H:%M:%S%.3fZ").to_string(),
        }
    }
}

/// 创建邮箱结果（含一次性返回的明文 access_token）
#[derive(Debug, Serialize)]
pub struct CreateMailboxResult {
    #[serde(flatten)]
    pub mailbox: MailboxVO,
    pub access_token: String,
}
