use ex3_common_error_info::ErrorInfo;

use ex3_canister_error::prelude::Error;
use ex3_canister_error::{impl_error_info_conversion, ErrorCode, ErrorKind};

/// The error type for asset vault
#[derive(Error, Debug, PartialEq, Clone, Eq)]
pub enum BlockchainError {
    #[error("Failed by parent hash not match")]
    FailedByParentHashDoesNotMatch,
    #[error("Failed by block hash not match")]
    FailedByInvalidTimestamp,
    #[error("Failed by invalid version")]
    FailedByInvalidVersion,
    #[error("Non-existent block height")]
    NonExistentBlockHeight,
}

impl ErrorCode for BlockchainError {
    fn error_code(&self) -> u32 {
        let root_code = ErrorKind::error_code(&ErrorKind::Blockchain);
        match self {
            Self::FailedByParentHashDoesNotMatch => root_code + 1,
            Self::FailedByInvalidTimestamp => root_code + 2,
            Self::FailedByInvalidVersion => root_code + 3,
            Self::NonExistentBlockHeight => root_code + 4,
        }
    }
}

impl_error_info_conversion!(BlockchainError);
