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

export async function listRiskRules(params?: Record<string, string>): Promise<RiskRule[]> {
  const query = params ? '?' + new URLSearchParams(params).toString() : '';
  return apiClient<RiskRule[]>(`/api/v1/agent/risk-rules${query}`);
}

export async function createRiskRule(
  rule: Omit<RiskRule, 'id' | 'createdAt' | 'updatedAt'>,
): Promise<RiskRule> {
  return apiClient<RiskRule>('/api/v1/agent/risk-rules', {
    method: 'POST',
    body: rule,
  });
}

export async function updateRiskRule(id: string, data: Partial<RiskRule>): Promise<RiskRule> {
  return apiClient<RiskRule>(`/api/v1/agent/risk-rules/${id}`, {
    method: 'PUT',
    body: data,
  });
}

export async function deleteRiskRule(id: string): Promise<void> {
  await apiClient(`/api/v1/agent/risk-rules/${id}`, {
    method: 'DELETE',
  });
}
