import apiClient from './client'
import type { Category, CategoryListItem, CategoryCreate, CategoryUpdate } from '@/types'

export const categoriesApi = {
  async list(includeInactive = false, accountOnly = false): Promise<CategoryListItem[]> {
    const response = await apiClient.get<CategoryListItem[]>('/categories', {
      params: { include_inactive: includeInactive, account_only: accountOnly },
    })
    return response.data
  },

  async get(id: string): Promise<Category> {
    const response = await apiClient.get<Category>(`/categories/${id}`)
    return response.data
  },

  async create(data: CategoryCreate): Promise<Category> {
    const response = await apiClient.post<Category>('/categories', data)
    return response.data
  },

  async update(id: string, data: CategoryUpdate): Promise<Category> {
    const response = await apiClient.put<Category>(`/categories/${id}`, data)
    return response.data
  },

  async delete(id: string): Promise<void> {
    await apiClient.delete(`/categories/${id}`)
  },
}

export default categoriesApi
