// 流程管理接口
import request from '../index'
// import type { IlistQuery } from '@/views/system/process/process'
const prefix = '/system/flow'

// 列表
export function getProcessList(data: { offset: number; limit: number }) {
  return request({
    url: `${prefix}/listPage?offset=${data.offset}&limit=${data.limit}`,
    method: 'post',
    data,
  })
}

// 删除
export function delProcessList(id: string) {
  const param = {
    deployId: id,
  }
  return request({
    url: `${prefix}/delete`,
    method: 'post',
    data: param,
  })
}
// 废止
export function updateState(id: string, state: number) {
  const param = {
    deployId: id,
    state,
  }
  return request({
    url: `${prefix}/updateState`,
    method: 'post',
    data: param,
  })
}

// 加载流程定义
export function unloadProcess(params: Object) {
  const param = {
    _value: params,
  }
  return request({
    url: `${prefix}/jsonToBpmn`,
    method: 'post',
    data: param,
  })
}

// 流程定义编辑
export function editProcess(params: Object) {
  const param = {
    _value: params,
  }
  return request({
    url: `${prefix}/update`,
    method: 'post',
    data: param,
  })
}

// 新建流程
export function addProcess(params: Object) {
  const param = {
    _value: params,
  }
  return request({
    url: `${prefix}/jsonToBpmn`,
    method: 'post',
    data: param,
  })
}

// 获取流程定义详情
export function getProcessDetail(formId: string) {
  const param = {
    formId,
  }
  return request({
    url: `${prefix}/detail`,
    method: 'post',
    data: param,
  })
}

// 获取关联业务列表
export function getBusinessList() {
  return request({
    url: `${prefix}/flowFormList`,
    method: 'get',
  })
}

// 获取发起人的主管层级数
export function getDirectorLevel(userId: number | string) {
  return request({
    url: `${prefix}/directorLevel`,
    method: 'get',
    params: { userId },
  })
}

// 导出列表
export function exportProcessList(data: {
  deploymentId: string
  suspensionState: string
  number: string
  name: string
  business: string
  person: string
  beginTime: string
  endTime: string
  status: string
  ids: string[]
}) {
  return request({
    url: `${prefix}/listExport`,
    method: 'post',
    responseType: 'blob',
    data,
  })
}
