//! Houses utils that do not have a home yet.
use nanoservices_utils::errors::{NanoServiceError, NanoServiceErrorStatus};

/// The error message for when a condition is not met.
pub static CONDITION_NOT_MET_ERR: &str = "Condition not met";

/// Checks if the condition is not met.
///
/// # Arguments
/// * `error`: The error to check
///
/// # Returns
/// * `bool`: True if the condition is not met, false otherwise
pub fn check_condition_not_met(error: &NanoServiceError) -> bool {
	error.status == NanoServiceErrorStatus::BadRequest && error.message == CONDITION_NOT_MET_ERR
}

/// Constructs a condition not met error.
///
/// # Returns
/// * `NanoServiceError`: The condition not met error
pub fn construct_condition_not_met_error() -> NanoServiceError {
	NanoServiceError::new(CONDITION_NOT_MET_ERR.to_string(), NanoServiceErrorStatus::BadRequest)
}

#[cfg(test)]
mod tests {

	use super::*;

	#[test]
	fn test_check_condition_not_met_true() {
		let error = NanoServiceError::new(
			CONDITION_NOT_MET_ERR.to_string(),
			NanoServiceErrorStatus::BadRequest,
		);
		assert!(check_condition_not_met(&error));
	}

	#[test]
	fn test_check_condition_not_met_false() {
		let error = NanoServiceError::new(
			"Some other error".to_string(),
			NanoServiceErrorStatus::BadRequest,
		);
		assert!(!check_condition_not_met(&error));
	}

	#[test]
	fn test_construct_condition_not_met_error() {
		let error = construct_condition_not_met_error();
		assert_eq!(error.status, NanoServiceErrorStatus::BadRequest);
		assert_eq!(error.message, CONDITION_NOT_MET_ERR);
	}
}
