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

enum Api {
  category = '/basic-api/category/queryAll',
  attribute = '/basic-api/specification/list',
  delete = '/basic-api/specification/delete',
  update = '/basic-api/specification/update',
  save = '/basic-api/specification/save',
  uploadBanner = '/basic-api/sys/oss/upload',
  addCategory = '/basic-api/category/save',
  updateCategory = '/basic-api/category/update',
  deleteCategory = '/basic-api/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,
    },
  });
