import request from "@/router/axios";
import { getToken } from "@/util/auth";

export const getList = (current, size, params) => {
  return request({
    url: "/api/jobslink-api/resource/oss/list",
    method: "get",
    params: {
      ...params,
      current,
      size
    }
  });
};

export const getDetail = id => {
  return request({
    url: "/api/jobslink-api/resource/oss/detail",
    method: "get",
    params: { id }
  });
};

export const remove = ids => {
  return request({
    url: "/api/jobslink-api/resource/oss/remove",
    method: "post",
    params: {
      ids
    }
  });
};

export const add = row => {
  return request({
    url: "/api/jobslink-api/resource/oss/submit",
    method: "post",
    data: row
  });
};

export const update = row => {
  return request({
    url: "/api/jobslink-api/resource/oss/submit",
    method: "post",
    data: row
  });
};

export const enable = id => {
  return request({
    url: "/api/jobslink-api/resource/oss/enable",
    method: "post",
    params: { id }
  });
};

export const putFile = type =>
  `/api/jobslink-api/resource/file/save?Jobslink-Auth=${getToken()}?bussinessType=${type ||
    11}`;

export const putFileObj = type =>
  `/api/jobslink-api/resource/file/upload/file?Jobslink-Auth=${getToken()}?bussinessType=${type ||
18}`;

export const putFileFun = (file, onUploadProgress) => {
  const data = new FormData();
  data.append("file", file);

  return request({
    url: "/api/jobslink-api/resource/file/save?bussinessType=11",
    method: "post",
    headers: { "Content-Type": "multipart/form-data" },
    data,
    onUploadProgress
  });
};

export const putFileUpload = (file, type, onUploadProgress) => {
  const data = new FormData();
  data.append("file", file);

  return request({
    url: "/api/jobslink-api/resource/file/save?bussinessType=" + type,
    method: "post",
    headers: { "Content-Type": "multipart/form-data" },
    data,
    onUploadProgress
  });
};
