import { api } from './client'

function toQuery(params) {
  const q = new URLSearchParams()
  for (const [key, value] of Object.entries(params)) {
    if (value !== null && value !== undefined && value !== '') {
      q.set(key, String(value))
    }
  }
  const s = q.toString()
  return s ? `?${s}` : ''
}

export function fetchReconciliationAlerts({
  checkType,
  resolved,
  page = 1,
  pageSize = 50,
} = {}) {
  return api.get(`/api/v1/reconciliation-alerts${toQuery({
    checkType,
    resolved,
    page,
    pageSize,
  })}`)
}
