// {{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

import type { Command } from 'commander';
import axios from 'axios';

import { AuthManager } from '../auth/auth-manager.js';
import { buildApiUrl } from '../core/api-url-builder.js';
import { loadConfig } from '../core/config-manager.js';

export function registerTestConnectionCommand(program: Command): void {
  program
    .command('test-connection')
    .description('Verify the configured API URL and credentials are reachable')
    .action(async () => {
      const config = loadConfig();
      const authManager = new AuthManager(config.auth_method);
      const headers = await authManager.applyAuthHeaders({}, 'GET', config.url, 'stdio');
      try {
        await axios.get(buildApiUrl(config.url, '/'), { headers, timeout: config.timeout_ms });
        console.log('connection OK');
      } catch (error) {
        console.error('connection failed:', error instanceof Error ? error.message : error);
        process.exitCode = 1;
      }
    });
}
