// Bitbucket Data Center MCP server — generated by mcpify. Do not hand-edit.

use std::collections::HashMap;
use std::time::Duration;

use bitbucket_dc_mcp::auth::auth_manager::AuthManager;
use bitbucket_dc_mcp::core::api_url_builder::build_api_url;
use bitbucket_dc_mcp::core::config_manager::load_config;
use bitbucket_dc_mcp::core::config_schema::Transport;

pub async fn run() -> anyhow::Result<()> {
    let config = load_config(serde_json::Map::new())?;
    let mut auth_manager = AuthManager::new(config.auth_method);
    let headers = auth_manager
        .apply_auth_headers(HashMap::new(), "GET", &config.url, Transport::Stdio, None)
        .await?;

    let url = build_api_url(&config.url, "/", &[])?;
    let client = reqwest::Client::new();
    let mut request = client
        .get(&url)
        .timeout(Duration::from_millis(config.timeout_ms));
    for (key, value) in headers {
        request = request.header(key, value);
    }

    match request.send().await {
        Ok(_) => {
            println!("connection OK");
            Ok(())
        }
        Err(err) => {
            eprintln!("connection failed: {err}");
            std::process::exit(1);
        }
    }
}
