import { defHttp } from '/@/utils/http/axios';
import { PageParams, updateItem, RentListGetResultModel, addCategoryParams } from './model';
import { Result, UploadFileParams } from '/#/axios';

enum Api {
  category = '/zfb-api/zfb/category/queryAll',
  attribute = '/zfb-api/zfb/specification/list',
  delete = '/zfb-api/zfb/specification/delete',
  update = '/zfb-api/zfb/specification/update',
  save = '/zfb-api/zfb/specification/save',
  uploadBanner = '/zfb-api/zfb/sys/oss/upload',
  addCategory = '/zfb-api/zfb/category/save',
  updateCategory = '/zfb-api/zfb/category/update',
  deleteCategory = '/zfb-api/zfb/category/delete',
}

/**
 * @description: Get sample list value
 */

export const categoryApi = (params: PageParams) =>
  defHttp.post<RentListGetResultModel>({
    url: Api.category,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const attributeListApi = (params: PageParams) =>
  defHttp.post<RentListGetResultModel>({
    url: Api.attribute,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const updateItemApi = (params: PageParams) =>
  defHttp.post<RentListGetResultModel>({
    url: Api.update,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const saveItemApi = (params: updateItem) =>
  defHttp.post<RentListGetResultModel>({
    url: Api.save,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const attributeDeleteApi = (params: string) =>
  defHttp.post<RentListGetResultModel>({
    url: Api.delete,
    params: [params],
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export function uploadBannerApi(
  params: UploadFileParams,
  // onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<Result>(
    {
      url: Api.uploadBanner,
      // onUploadProgress,
    },
    params,
  );
}
export const addCategoryApi = (params: addCategoryParams) =>
  defHttp.post<RentListGetResultModel>({
    url: Api.addCategory,
    params: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const updateCategoryApi = (params: addCategoryParams) =>
  defHttp.post<Result>({
    url: Api.updateCategory,
    params: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const deleteCategoryApi = (params: string[]) =>
  defHttp.post<Result>({
    url: Api.deleteCategory,
    params: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
