use actix_web::http::StatusCode;

#[derive(Debug)]
pub enum ApiError {
	ProtectedSchedule,
	InternalError(String),
}

impl ApiError {
	pub fn get_code(&self) -> StatusCode {
		match self {
			ApiError::ProtectedSchedule => StatusCode::FORBIDDEN,
			ApiError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
		}
	}
}

impl From<&ApiError> for String {
	fn from(err: &ApiError) -> Self {
		match err {
			ApiError::ProtectedSchedule => String::from("the targeted schedule is protected"),
			ApiError::InternalError(msg) => msg.clone(),
		}
	}
}