import request from './request'
import type {
  Category,
  CategoryTree,
  CreateCategoryRequest,
  UpdateCategoryRequest,
  CategoryFilter,
  PaginatedResult,
} from '@/types'

export const categoriesApi = {
  // Get categories list
  getCategoriesList: (params: CategoryFilter) => {
    return request.get<any, PaginatedResult<Category>>('/categories', { params })
  },

  // Get category tree
  getCategoryTree: () => {
    return request.get<any, CategoryTree[]>('/categories')
  },

  // Get category by id
  getCategoryById: (id: string) => {
    return request.get<any, Category>(`/categories/${id}`)
  },

  // Create category
  createCategory: (data: CreateCategoryRequest) => {
    return request.post<any, Category>('/categories', data)
  },

  // Update category
  updateCategory: (id: string, data: UpdateCategoryRequest) => {
    return request.patch<any, Category>(`/categories/${id}`, data)
  },

  // Delete category
  deleteCategory: (id: string) => {
    return request.delete(`/categories/${id}`)
  },
}