//! Server runtime configuration.
//!
//! Configuration that varies per deployment (e.g. `DATABASE_URL`) and is only
//! needed by the server binary. These values are read from the process
//! environment at startup, not baked into the WASM bundle.
//!
//! The server binary calls `dotenvy::dotenv()` in `main` before
//! [`ServerConfig::load`]. Hydrant reads its own `HYDRANT_*` variables via its
//! own `Config::from_env`; this struct holds only app-level server config and is
//! the single place server-side environment variables are read.

use std::env;

/// App-level server configuration loaded from the environment.
#[derive(Debug, Clone)]
pub struct ServerConfig {
    /// sqlx connect URL, e.g. `sqlite:./data/polymodel.db`.
    pub database_url: String,
}

impl ServerConfig {
    /// Read the server config from the process environment.
    ///
    /// Call `dotenvy::dotenv()` first so variables in `.env` are visible. This
    /// is the only place server-side env reads happen.
    pub fn load() -> Self {
        let database_url =
            env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite:./data/polymodel.db".to_string());
        Self { database_url }
    }
}
