use crate::core::config::Config;
use crate::core::error::Result;
use crate::gitlab::GitLabClient;

pub struct AuthTestResult {
    pub username: String,
    pub name: String,
    pub base_url: String,
}

pub async fn run_auth_test(config_path: Option<&str>) -> Result<AuthTestResult> {
    let config = Config::load(config_path)?;

    let token = config.gitlab.resolve_token()?;

    let client = GitLabClient::new(&config.gitlab.base_url, &token, None);

    let user = client.get_current_user().await?;

    Ok(AuthTestResult {
        username: user.username,
        name: user.name,
        base_url: config.gitlab.base_url,
    })
}
