import { apiRequest } from './client'

export function listCollection(collection, params = {}) {
  const qs = new URLSearchParams()
  if (params.skip != null) qs.set('skip', String(params.skip))
  if (params.limit != null) qs.set('limit', String(params.limit))
  const q = qs.toString()
  return apiRequest(`/${collection}${q ? `?${q}` : ''}`)
}

export function getItem(collection, id) {
  return apiRequest(`/${collection}/${id}`)
}

export function createItem(collection, body) {
  return apiRequest(`/${collection}`, { method: 'POST', body })
}

export function updateItem(collection, id, body) {
  return apiRequest(`/${collection}/${id}`, { method: 'PUT', body })
}

export function deleteItem(collection, id) {
  return apiRequest(`/${collection}/${id}`, { method: 'DELETE' })
}
