use compliance_core::DashboardConfig;

use super::error::DashboardError;

pub fn load_config() -> Result<DashboardConfig, DashboardError> {
    Ok(DashboardConfig {
        mongodb_uri: std::env::var("MONGODB_URI")
            .map_err(|_| DashboardError::Config("Missing MONGODB_URI".to_string()))?,
        mongodb_database: std::env::var("MONGODB_DATABASE")
            .unwrap_or_else(|_| "compliance_scanner".to_string()),
        agent_api_url: std::env::var("AGENT_API_URL")
            .unwrap_or_else(|_| "http://localhost:3001".to_string()),
        dashboard_port: std::env::var("DASHBOARD_PORT")
            .ok()
            .and_then(|p| p.parse().ok())
            .unwrap_or(8080),
        mcp_endpoint_url: std::env::var("MCP_ENDPOINT_URL")
            .ok()
            .filter(|v| !v.is_empty()),
    })
}
