import request from "@/util/oaRequest"

// 流程任务
export function listFlowTask(query) {
  return request({
    url: '/hrm/flow/task/list',
    method: 'get',
    params: query
  })
}

export function updateFlowInstance(data) {
  return request({
    url: '/hrm/flow/instance',
    method: 'put',
    data
  })
}

export function listTodoFlowTask(assigneeUserId) {
  return request({
    url: '/hrm/flow/task/todo',
    method: 'get',
    params: { assigneeUserId }
  })
}

// 业务维度：按 bizType + bizId 查询当前待办任务（后端需提供）
export function getTodoTaskByBiz(bizType, bizId, assigneeUserId) {
  return request({
    url: '/hrm/flow/task/todoByBiz',
    method: 'get',
    params: { bizType, bizId, assigneeUserId }
  })
}

export function approveFlowTask(taskId, data) {
  return request({
    url: `/hrm/flow/task/${taskId}/approve`,
    method: 'post',
    data
  })
}

export function rejectFlowTask(taskId, data) {
  return request({
    url: `/hrm/flow/task/${taskId}/reject`,
    method: 'post',
    data
  })
}

export function withdrawFlowTask(taskId, data) {
  return request({
    url: `/hrm/flow/task/${taskId}/withdraw`,
    method: 'post',
    data
  })
}

export function transferFlowTask(taskId, data) {
  return request({
    url: `/hrm/flow/task/${taskId}/transfer`,
    method: 'post',
    params: data
  })
}

export function ccFlowTask(data) {
  return request({
    url: '/hrm/flow/cc',
    method: 'post',
    data
  })
}

// 流程动作/表单
export function listFlowAction(query) {
  return request({
    url: '/hrm/flow/action/list',
    method: 'get',
    params: query
  })
}

export function listFlowFormData(query) {
  return request({
    // 后端 Controller: HrmFlowFormDataController
    // @RequestMapping("/hrm/flow/form") + @GetMapping("/list")
    url: '/hrm/flow/form/list',
    method: 'get',
    params: query
  })
}

// 流程实例
export function listFlowInstance(query) {
  return request({
    url: '/hrm/flow/instance/list',
    method: 'get',
    params: query
  })
}

// 我的申请（我发起的流程实例）
export function listMyFlowInstance(query) {
  return request({
    url: '/hrm/flow/instance/myList',
    method: 'get',
    params: query
  })
}

export function getFlowInstance(instId) {
  return request({
    url: `/hrm/flow/instance/${instId}`,
    method: 'get'
  })
}

export function queryInstanceByBiz(bizType, bizId) {
  return request({
    url: '/hrm/flow/instance/all',
    method: 'get',
    params: { bizType, bizId }
  })
}

export function listFlowForm(query) {
  return request({
    url: '/hrm/flow/form/list',
    method: 'get',
    params: query
  })
}

export function getFlowForm(formId) {
  return request({
    url: `/hrm/flow/form/${formId}`,
    method: 'get'
  })
}

// 流程模板
export function listFlowTemplate(query) {
  return request({
    url: '/hrm/flow/template/list',
    method: 'get',
    params: query
  })
}

export function getFlowTemplate(tplId) {
  return request({
    url: `/hrm/flow/template/${tplId}`,
    method: 'get'
  })
}

export function addFlowTemplate(data) {
  return request({
    url: '/hrm/flow/template',
    method: 'post',
    data
  })
}

export function updateFlowTemplate(data) {
  return request({
    url: '/hrm/flow/template',
    method: 'put',
    data
  })
}

export function delFlowTemplate(tplIds) {
  return request({
    url: `/hrm/flow/template/${tplIds}`,
    method: 'delete'
  })
}

// 流程节点
export function listFlowNode(query) {
  return request({
    url: '/hrm/flow/node/list',
    method: 'get',
    params: query
  })
}

export function getFlowNode(nodeId) {
  return request({
    url: `/hrm/flow/node/${nodeId}`,
    method: 'get'
  })
}

export function addFlowNode(data) {
  return request({
    url: '/hrm/flow/node',
    method: 'post',
    data
  })
}

export function updateFlowNode(data) {
  return request({
    url: '/hrm/flow/node',
    method: 'put',
    data
  })
}

export function delFlowNode(nodeIds) {
  return request({
    url: `/hrm/flow/node/${nodeIds}`,
    method: 'delete'
  })
}
