/// Legacy numeric error code.
///
/// New protocol-facing code should use the stable identity generated by
/// `OrionError` (`identity = "biz.xxx"`, `category = ...`) as the machine key.
/// This trait remains for compatibility with older numeric-code integrations
/// and built-in `UvsReason` helpers.
pub trait ErrorCode {
    fn error_code(&self) -> i32 {
        500
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(
    feature = "serde",
    derive(serde::Serialize, serde::Deserialize),
    serde(rename_all = "lowercase")
)]
pub enum ErrorCategory {
    Conf,
    Biz,
    Logic,
    Sys,
}

impl ErrorCategory {
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Conf => "conf",
            Self::Biz => "biz",
            Self::Logic => "logic",
            Self::Sys => "sys",
        }
    }
}

pub trait ErrorIdentityProvider {
    fn stable_code(&self) -> &'static str;

    fn error_category(&self) -> ErrorCategory;
}
