import { http } from "@/utils/http";

export interface CategoryQuery extends BasePageQuery {
  categoryName?: string;
  sort?: number;
}

/** 分类DTO */
export interface CategoryDTO {
  categoryId?: number;
  categoryName?: string;
  sort?: number;
  description?: string;
  creatorId?: number;
  createTime?: Date;
  updaterId?: number;
  updateTime?: Date;
}

/** 分类请求参数 */
export interface CategoryRequest {
  categoryName: string;
  sort: number;
  description?: string;
}

/** 获取分类列表 */
export const getCategoryListApi = (params?: CategoryQuery) => {
  return http.request<ResponseData<PageDTO<CategoryDTO>>>("get", "/shop/category/list", {
    params
  });
};

/** 获取分类列表 */
export const getCategoryAllApi = () => {
  return http.request<ResponseData<Array<CategoryDTO>>>("get", "/shop/category/all", {

  });
};

/** 新增分类 */
export const addCategoryApi = (data: CategoryRequest) => {
  return http.request<ResponseData<void>>("post", "/shop/category", {
    data
  });
};

/** 编辑分类 */
export const updateCategoryApi = (categoryId: number, data: CategoryRequest) => {
  return http.request<ResponseData<void>>("put", `/shop/category/${categoryId}`, {
    data
  });
};

/** 删除分类 */
export const deleteCategoryApi = (categoryId: number | string) => {
  return http.request<ResponseData<void>>("delete", `/shop/category/${categoryId}`);
};

/** 批量导出分类 */
export const exportCategoryExcelApi = (params: CategoryQuery, fileName: string) => {
  return http.download("/shop/category/excel", fileName, {
    params
  });
};
