import { apiClient } from '@/infrastructure/api/api-client';
import type { AlertRule } from '@/domain/entities/alert-rule';

export async function createAlertRule(
  rule: Omit<AlertRule, 'id' | 'createdAt' | 'updatedAt'>,
): Promise<AlertRule> {
  return apiClient<AlertRule>('/api/v1/monitor/alerts/rules', {
    method: 'POST',
    body: rule,
  });
}

export async function updateAlertRule(id: string, data: Partial<AlertRule>): Promise<AlertRule> {
  return apiClient<AlertRule>(`/api/v1/monitor/alerts/rules/${id}`, {
    method: 'PUT',
    body: data,
  });
}

export async function deleteAlertRule(id: string): Promise<void> {
  await apiClient(`/api/v1/monitor/alerts/rules/${id}`, {
    method: 'DELETE',
  });
}

export async function toggleAlertRule(id: string, enabled: boolean): Promise<void> {
  await apiClient(`/api/v1/monitor/alerts/rules/${id}/toggle`, {
    method: 'PATCH',
    body: { enabled },
  });
}
