/**
 * Topics API — listing, creation, update, deletion, AI suggestion.
 *
 * Consumers: stores/topics.js
 */

import { request, jsonRequest } from './utils.js'

export function listTopics() {
  return request('/api/topics')
}

export function createTopic({ name, description = '', color = '#6366f1' }) {
  return jsonRequest('/api/topics', 'POST', { name, description, color })
}

export function updateTopic(id, patch) {
  return jsonRequest(`/api/topics/${id}`, 'PATCH', patch)
}

export function deleteTopic(id) {
  return request(`/api/topics/${id}`, { method: 'DELETE' })
}

export function suggestTopics(documentId) {
  return jsonRequest('/api/topics/suggest', 'POST', { document_id: documentId })
}
