//! Application configuration.

/// Application configuration loaded from environment variables.
#[derive(Clone)]
pub struct AppConfig {
    pub app_name: String,
    pub jwt_secret: String,
    pub database_url: String,
    pub host: String,
    pub port: u16,
    pub stripe_secret_key: String,
    pub stripe_webhook_secret: String,
    pub stripe_price_id: String,
    pub app_url: String,
}

impl AppConfig {
    /// Load configuration from environment variables.
    pub fn from_env() -> Self {
        Self {
            app_name: std::env::var("APP_NAME").unwrap_or_else(|_| "{{project_name_pascal}}".into()),
            jwt_secret: std::env::var("JWT_SECRET").expect("JWT_SECRET must be set"),
            database_url: std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"),
            host: std::env::var("HOST").unwrap_or_else(|_| "0.0.0.0".into()),
            port: std::env::var("PORT")
                .unwrap_or_else(|_| "3000".into())
                .parse()
                .expect("PORT must be a number"),
            stripe_secret_key: std::env::var("STRIPE_SECRET_KEY").expect("STRIPE_SECRET_KEY must be set"),
            stripe_webhook_secret: std::env::var("STRIPE_WEBHOOK_SECRET").expect("STRIPE_WEBHOOK_SECRET must be set"),
            stripe_price_id: std::env::var("STRIPE_PRICE_ID").expect("STRIPE_PRICE_ID must be set"),
            app_url: std::env::var("APP_URL").unwrap_or_else(|_| "http://localhost:3000".into()),
        }
    }
}
