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

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

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

export function createTopic({ name, description = '', color = '#6366f1' }) {
  return request('/api/topics', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ name, description, color }),
  })
}

export function updateTopic(id, patch) {
  return request(`/api/topics/${id}`, {
    method: 'PATCH',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(patch),
  })
}

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

export function suggestTopics(documentId) {
  return request('/api/topics/suggest', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ document_id: documentId }),
  })
}
