import request from '@/utils/request';
import type { Page } from '@/types/base';
import type {
  FormCategoryQuery,
  FormCategoryResponse,
  FormCategoryRequest,
} from './types';

const BASE_URL = '/api/v1/forms/categories';

/**
 * 分页查询分类
 */
export const getCategories = (params?: FormCategoryQuery) =>
  request.get<Page<FormCategoryResponse>>(`${BASE_URL}/page`, { params });

/**
 * 查询分类详情
 */
export const getCategoryById = (id: number) =>
  request.get<FormCategoryResponse>(`${BASE_URL}/${id}`);

/**
 * 查询所有启用的分类（常用）
 */
export const getEnabledCategories = () =>
  request.get<FormCategoryResponse[]>(`${BASE_URL}/enabled`);

/**
 * 创建分类
 */
export const createCategory = (data: FormCategoryRequest) =>
  request.post<FormCategoryResponse>(BASE_URL, data);

/**
 * 更新分类
 */
export const updateCategory = (id: number, data: FormCategoryRequest) =>
  request.put<FormCategoryResponse>(`${BASE_URL}/${id}`, data);

/**
 * 删除分类
 */
export const deleteCategory = (id: number) =>
  request.delete(`${BASE_URL}/${id}`);

