//! 邮箱事务状态枚举 (对齐 C 层 ec_mbx_status_t / C# MailboxStatus)

/// 邮箱事务状态 (对齐 C 层 `ec_mbx_status_t`).
///
/// 数值与 C 层保持一致以支持 FFI 直接转换.
/// - 正值 = 成功 / 进行中
/// - 负值 = 错误
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum MailboxStatus {
    /// 事务进行中 (初始状态)
    Pending        =  0,
    /// 事务成功完成
    Success        =  1,
    /// 事务超时
    Timeout        = -1,
    /// 事务被取消
    Cancelled      = -2,
    /// 邮箱层错误 (对端返回 MBX ERROR 帧)
    MailboxError   = -3,
    /// 协议类型不匹配
    ProtoMismatch  = -4,
    /// counter 字段不匹配 (重复响应或乱序)
    CounterFail    = -5,
    /// 工作计数 (WKC) 校验失败
    WkcFail        = -6,
    /// 内存分配失败
    NoMemory       = -7,
    /// 无效参数
    InvalidArg     = -8,
    /// 未实现
    NotImplemented = -9,
}

impl From<i32> for MailboxStatus {
    fn from(v: i32) -> Self {
        match v {
            0 => Self::Pending,
            1 => Self::Success,
            -1 => Self::Timeout,
            -2 => Self::Cancelled,
            -3 => Self::MailboxError,
            -4 => Self::ProtoMismatch,
            -5 => Self::CounterFail,
            -6 => Self::WkcFail,
            -7 => Self::NoMemory,
            -8 => Self::InvalidArg,
            -9 => Self::NotImplemented,
            _ => Self::InvalidArg,
        }
    }
}

impl Default for MailboxStatus {
    fn default() -> Self { Self::Pending }
}
