import request from "@/utils/request";

export function LIST(params) {
  return request({
    url: "/pu/contract/list",
    method: "GET",
    params: params,
  });
}

export function ITEM(data) {
  return request({
    url: `/pu/contract/${data}`,
    method: "GET",
  });
}

export function ADD(data) {
  return request({
    url: "/pu/contract/add",
    method: "POST",
    data: data,
  });
}

export function EXPORT(data) {
  return request({
    url: "/pu/contract/export",
    method: "POST",
    data: data,
  });
}

export function IMPORT(params) {
  return request({
    url: "/pu/contract/importData",
    method: "GET",
    params: params,
  });
}

export function EDIT(data) {
  return request({
    url: "/pu/contract/edit",
    method: "PUT",
    data: data,
  });
}

export function REMOVE(data) {
  return request({
    url: `/pu/contract/${data}`,
    method: "DELETE",
  });
}

export function TERMINATION(params) {
  return request({
    url: `/pu/contract/termination`,
    method: "PUT",
    params: params,
  });
}

export function PIGEONHOLE(data, params) {
  return request({
    url: `/pu/contract/pigeonhole`,
    method: "PUT",
    data: data,
    params: params,
  });
}

export function ALTERATION(data) {
  return request({
    url: `/pu/contract/alteration`,
    method: "POST",
    data: data,
  });
}

export function CODE() {
  return request({
    url: "/pu/contract/generateNo",
    method: "GET",
  });
}

export function SUBMIT(data) {
  return request({
    url: `/pu/contract/submit/${data}`,
    method: "GET",
  });
}

export function LINKAGREEMENT(data) {
  return request({
    url: `/pu/contract/agreement/getCode/${data}`,
    method: "GET",
  });
}

export const ToOA =(userName, fdId) => {
  return request({
    url: `/oaflow/redirectToOa/${userName}/${fdId}`,
    method: 'get',
  })
}

const switchUrl = (prop) => {
  if (prop === "contractItemList") return "/pu/contract/item";
  if (prop === "contractClauseList") return "/pu/contract/clause";
  if (prop === "contractExpenseList") return "/pu/contract/expense";
  if (prop === "contractAgreementList") return "/pu/contract/agreement";
  if (prop === "contractApplyOrgList") return "/pu/contract/org";
};

export const TABLE = {
  LIST: function (params, name) {
    return request({
      url: `${switchUrl(name)}/list`,
      method: "GET",
      params: params,
    });
  },
  ADD: function (data, name) {
    return request({
      url: `${switchUrl(name)}/add`,
      method: "POST",
      data: data,
    });
  },
  EDIT: function (data, name) {
    return request({
      url: `${switchUrl(name)}`,
      method: "PUT",
      data: data,
    });
  },
  REMOVE: function (data, name) {
    return request({
      url: `${switchUrl(name)}/${data}`,
      method: "DELETE",
    });
  },
};
