import request from '@/utils/request';
import type { Page } from '@/types/base';
import type {
  ApplicationCategoryQuery,
  ApplicationCategoryResponse,
  ApplicationCategoryRequest,
} from './types';

const BASE_URL = '/api/v1/application-category';

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

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

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

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

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

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

