use std::path::PathBuf; use anyhow::{Context, Result}; #[derive(Clone, Debug)] pub struct AppConfig { pub database_url: String, pub jwt_secret: String, pub session_expiry_days: i64, pub admin_password_hash: String, pub event_name: String, pub event_slug: String, pub media_path: PathBuf, pub app_port: u16, } impl AppConfig { pub fn from_env() -> Result { Ok(Self { database_url: std::env::var("DATABASE_URL") .context("DATABASE_URL must be set")?, jwt_secret: std::env::var("JWT_SECRET") .context("JWT_SECRET must be set")?, session_expiry_days: std::env::var("SESSION_EXPIRY_DAYS") .unwrap_or_else(|_| "30".to_string()) .parse() .context("SESSION_EXPIRY_DAYS must be a number")?, admin_password_hash: std::env::var("ADMIN_PASSWORD_HASH") .unwrap_or_default(), event_name: std::env::var("EVENT_NAME") .unwrap_or_else(|_| "EventSnap".to_string()), event_slug: std::env::var("EVENT_SLUG") .context("EVENT_SLUG must be set")?, media_path: PathBuf::from( std::env::var("MEDIA_PATH").unwrap_or_else(|_| "/media".to_string()), ), app_port: std::env::var("APP_PORT") .unwrap_or_else(|_| "3000".to_string()) .parse() .context("APP_PORT must be a number")?, }) } }