mod client;
mod config;
mod formatters;
mod macros;
mod mcp;
mod tools;
mod types;

#[tokio::main]
async fn main() {
    // Load .env file if present
    let _ = dotenvy::dotenv();

    let config = match config::Config::from_env() {
        Ok(c) => c,
        Err(e) => {
            eprintln!("Configuration error: {e}");
            eprintln!("Please set the required environment variables (CONFLUENCE_HOST, CONFLUENCE_API_TOKEN).");
            std::process::exit(1);
        }
    };

    let client = client::ConfluenceClient::new(config);

    eprintln!("Confluence MCP Server running on stdio");

    if let Err(e) = mcp::run(client).await {
        eprintln!("Fatal error: {e}");
        std::process::exit(1);
    }
}
