use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppConfig {
pub name: String,
pub version: String,
#[serde(default)]
pub description: Option<String>,
#[serde(default)]
pub author: Option<String>,
#[serde(default)]
pub debug: bool,
#[serde(default)]
pub environment: Environment,
}
impl Default for AppConfig {
fn default() -> Self {
Self {
name: "Backbone Application".to_string(),
version: "1.0.0".to_string(),
description: None,
author: None,
debug: true,
environment: Environment::Development,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum Environment {
#[default]
Development,
Staging,
Production,
}
impl std::fmt::Display for Environment {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Environment::Development => write!(f, "development"),
Environment::Staging => write!(f, "staging"),
Environment::Production => write!(f, "production"),
}
}
}
impl std::str::FromStr for Environment {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"development" | "dev" => Ok(Environment::Development),
"staging" | "stage" => Ok(Environment::Staging),
"production" | "prod" => Ok(Environment::Production),
_ => Err(format!("Unknown environment: {}", s)),
}
}
}