use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Debug, Clone)]
pub struct FrontMatter {
pub concept_type: Option<String>,
pub title: Option<String>,
pub description: Option<String>,
pub tags: Vec<String>,
pub custom: BTreeMap<String, serde_json::Value>,
#[allow(dead_code)]
pub raw_yaml: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ParseStatus {
Ok,
Partial,
Failed,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParseError {
pub stage: String,
pub message: String,
pub line: Option<usize>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LimitError {
pub limit_name: String,
pub limit_value: String,
pub actual_value: Option<String>,
pub message: String,
pub code: String,
}
impl LimitError {
pub fn new(limit_name: &str, limit_value: &str, message: &str) -> Self {
Self {
limit_name: limit_name.to_string(),
limit_value: limit_value.to_string(),
actual_value: None,
message: message.to_string(),
code: format!("LIMIT_EXCEEDED_{}", limit_name.to_uppercase()),
}
}
pub fn with_actual(mut self, actual: &str) -> Self {
self.actual_value = Some(actual.to_string());
self
}
}
impl std::fmt::Display for LimitError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{} (limit: {}, code: {})",
self.message, self.limit_value, self.code
)
}
}
impl std::error::Error for LimitError {}