use ex3_common_error_info::ErrorInfo;

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

/// The error type for pager
#[derive(Error, Debug, PartialEq, Clone, Eq)]
pub enum PagerError {
    #[error("Length of {field:?} must be in range [{min:?}, {max:?})")]
    ValueShouldBeInRangeError {
        field: String,
        min: usize,
        max: usize,
    },
}

impl ErrorCode for PagerError {
    fn error_code(&self) -> u32 {
        let root_code = ErrorKind::error_code(&ErrorKind::Common);
        let parent_code = CommonErrorKind::error_code(&CommonErrorKind::Pager);
        match self {
            PagerError::ValueShouldBeInRangeError { .. } => root_code + parent_code + 1,
        }
    }
}

impl_error_info_conversion!(PagerError);
