import { apiClient } from '@/infrastructure/api/api-client';
import type { HealthCheckResult } from '@/domain/entities/health-check';

export interface HealthCheckConfig {
  serverId: string;
  checkType: 'ping' | 'tcp' | 'http';
  intervalSeconds: number;
  timeoutMs: number;
  enabled: boolean;
}

export async function listHealthChecks(params?: Record<string, string>): Promise<HealthCheckResult[]> {
  const query = params ? '?' + new URLSearchParams(params).toString() : '';
  return apiClient<HealthCheckResult[]>(`/api/v1/monitoring/health-checks${query}`);
}

export async function configureHealthCheck(config: HealthCheckConfig): Promise<void> {
  await apiClient('/api/v1/monitoring/health-checks/configure', {
    method: 'PUT',
    body: config,
  });
}

export async function triggerHealthCheck(serverId: string): Promise<HealthCheckResult> {
  return apiClient<HealthCheckResult>(`/api/v1/monitoring/health-checks/${serverId}/trigger`, {
    method: 'POST',
  });
}
