import request from '@/utils/request.js'
import axios from "axios";
import {getToken} from "@/utils/auth";

//需求征集
export const getDemandInfo = (param) => {
  return request({
    url: '/workflow/mosr/requirement',
    method: "get",
    params: param
  });
};
export const filterRequirementName = (requirementName) => {
  return request({
    url: `/workflow/mosr/requirement/match/${requirementName}`,
    method: "get"
  });
};
export const getWorkflowInfo = () => {
  return request({
    url: '/workflow/mosr/requirement/process',
    method: "get"
  });
};
export const getInfo = (requirementId) => {
  return request({
    url: `/workflow/mosr/requirement/info/${requirementId}`,
    method: "get"
  });
};
export const getFormInfo = (requirementId) => {
  return request({
    url: `/workflow/mosr/requirement/form/${requirementId}`,
    method: "get"
  });
};
export const agreeTask = (data) => {
  return request({
    url: `/workflow/mosr/process/task/agree`,
    method: "post",
    data: data
  });
};
export const rejectTask = (data) => {
  return request({
    url: `/workflow/mosr/process/task/reject`,
    method: "post",
    data: data
  });
};

export const addRequirement = (data) => {
  return request({
    url: '/workflow/mosr/requirement',
    method: "post",
    data: data
  });
};
export const resubmit = (data) => {
  return request({
    url: '/workflow/mosr/requirement/resubmit',
    method: "post",
    data: data
  });
};
export const deleteFile = (fileId) => {
  return request({
    url: `/workflow/process/file/delete/${fileId}`,
    method: "delete"
  });
};
export const downloadFile = (fileId) => {
  return request({
    url: '/workflow/process/file/download',
    method: "get",
    responseType:'blob',
    params:{
      fileId:fileId
    }
  });
};
export const getCompanyOption = () => {
  return request({
    url: '/admin/mosr/sub/company/companyOption',
    method: "get"
  });
};
export const deleteDemand = (id) => {
  return request({
    url: `/workflow/mosr/requirement/${id}`,
    method: "delete"
  });
};
export const getRequirementStatePerm = () => {
  return request({
    url: '/workflow/mosr/requirement/prem/state',
    method: "get"
  });
};
export const downloadTemplate = (type) => {
  return request({
    url: '/workflow/mosr/attachment/download/template',
    method: "get",
    responseType:'blob',
    params:{
      type:type
    }
  });
};
export const downloadTemplateZip = (typeList) => {
  return axios.get(
    `${import.meta.env.VITE_BASE_URL}/workflow/mosr/attachment/download/pack?typeList=${typeList}`,
    {
      responseType: 'blob',
      headers: {
        Authorization: getToken()
      },
    }
  );
  // return request({
  //   url: '/workflow/mosr/attachment/download/pack',
  //   method: "get",
  //   responseType:'blob',
  //   params:{
  //     typeList:typeList
  //   }
  // });
};
