use std::error::Error;
use strum_macros::{Display, EnumString};

#[repr(u8)]
#[derive(Debug, Display, EnumString, Clone, Copy, Eq, PartialEq)]
pub enum DatError{
    // certificate
    InvalidCertificateFormat,
    UnknownSignatureAlgorithm,
    UnknownCryptoAlgorithm,
    InvalidSignatureKey,
    InvalidCryptoKey,
    GenerateSigningKeyError,
    NotExistsSigningKey,
    VerifyOnlyKeyIsPairKeyOption,
    EncryptError,
    DecryptError,
    SignError,
    CidNotFound,
    InvalidDatTtl,
    InvalidIssuanceDuration,

    // manager
    SigningKeyNotExists,
    DuplicatedCid,

    // util
    InvalidBase64Format,
    Utf8EncodeError,
    IoError,

    // Dat
    InvalidDat,
}

impl DatError {
    #[inline]
    pub fn is_critical(&self) -> bool {
        use DatError::*;
        match self {
            InvalidDat => false,
            _ => true,
        }
    }
}

impl Error for DatError {}

