use super::core::CoreConfig;
use super::types::{LogFormat, LogLevel};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Preset {
#[default]
Development,
Production,
Testing,
Benchmark,
}
impl Preset {
pub fn description(&self) -> &'static str {
match self {
Self::Development => "Development: Verbose logging, minimal features, fast startup",
Self::Production => "Production: Optimized settings, full monitoring, security enabled",
Self::Testing => {
"Testing: Minimal logging, deterministic behavior, all features disabled"
}
Self::Benchmark => {
"Benchmark: Maximum performance, monitoring disabled, consistent behavior"
}
}
}
pub fn apply_to_core(&self, mut core: CoreConfig) -> CoreConfig {
match self {
Self::Development => {
core.log_level = LogLevel::Debug;
core.log_format = LogFormat::Pretty;
core
}
Self::Production => {
core.log_level = LogLevel::Info;
core.log_format = LogFormat::Json;
core
}
Self::Testing => {
core.log_level = LogLevel::Error;
core.log_format = LogFormat::Compact;
core
}
Self::Benchmark => {
core.log_level = LogLevel::Warn;
core.log_format = LogFormat::Compact;
core
}
}
}
pub fn cache_enabled(&self) -> bool {
matches!(self, Self::Production)
}
pub fn monitoring_enabled(&self) -> bool {
matches!(self, Self::Production)
}
pub fn metrics_enabled(&self) -> bool {
matches!(self, Self::Production)
}
pub fn audit_enabled(&self) -> bool {
matches!(self, Self::Production)
}
pub fn max_concurrent_requests(&self) -> u32 {
match self {
Self::Development => 5,
Self::Production => 100,
Self::Testing => 1,
Self::Benchmark => 1,
}
}
pub fn request_timeout_seconds(&self) -> u64 {
match self {
Self::Development => 600, Self::Production => 300, Self::Testing => 10, Self::Benchmark => 3600, }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_preset_descriptions() {
assert!(!Preset::Development.description().is_empty());
assert!(!Preset::Production.description().is_empty());
assert!(!Preset::Testing.description().is_empty());
assert!(!Preset::Benchmark.description().is_empty());
}
#[test]
fn test_apply_to_core() {
let core = CoreConfig::default();
let dev = Preset::Development.apply_to_core(core.clone());
assert_eq!(dev.log_level, LogLevel::Debug);
assert_eq!(dev.log_format, LogFormat::Pretty);
let prod = Preset::Production.apply_to_core(core.clone());
assert_eq!(prod.log_level, LogLevel::Info);
assert_eq!(prod.log_format, LogFormat::Json);
}
#[test]
fn test_feature_flags() {
assert!(!Preset::Development.cache_enabled());
assert!(Preset::Production.cache_enabled());
assert!(!Preset::Testing.cache_enabled());
assert!(!Preset::Benchmark.cache_enabled());
assert!(!Preset::Development.monitoring_enabled());
assert!(Preset::Production.monitoring_enabled());
assert!(!Preset::Testing.monitoring_enabled());
assert!(!Preset::Benchmark.monitoring_enabled());
}
#[test]
fn test_resource_limits() {
assert_eq!(Preset::Development.max_concurrent_requests(), 5);
assert_eq!(Preset::Production.max_concurrent_requests(), 100);
assert_eq!(Preset::Testing.max_concurrent_requests(), 1);
assert_eq!(Preset::Development.request_timeout_seconds(), 600);
assert_eq!(Preset::Production.request_timeout_seconds(), 300);
}
#[test]
fn test_default_preset() {
assert_eq!(Preset::default(), Preset::Development);
}
}