import { request } from "@/utils/request";

/**
 * 获取待办列表
 * @param params
 */
export const getTodoList = (params) =>
  request({
    url: '/bpm/task/todo-page',
    method: 'GET',
    params,
  })

/**
 * 审批流程列表
 * @param params
 */
export const getApprovalList = (params) =>
  request({
    url: '/bpm/process-instance/my-page',
    method: 'GET',
    params,
  })

/**
 * 获取审批详情
 * @param params
 */
export const getApprovalDetail = (params) =>
  request({
    url: '/bpm/process-instance/get-approval-detail',
    method: 'GET',
    params,
  })

/**
 * 任务审批通过
 * @param id 任务ID
 * @param reason 理由
 */
export const approvalTask = (id, reason) =>
  request({
    url: '/bpm/task/approve',
    method: 'PUT',
    data: { id, reason, variables: {}, nextAssignees: {} },
  })


// 瑞恒审批通过
export const rhApproveTask = async (data) => {
  // return await request.put({ url: '/bpm/task/approve', data })
  return await request({
    url: '/bpm/task/approve',
    method: 'PUT',
    data,
  })
}

/**
 * 拒绝任务
 * @param id
 * @param reason
 */
export const rejectTask = (id, reason) =>
  request({
    url: '/bpm/task/reject',
    method: 'PUT',
    data: { id, reason },
  })

/**
 * 转派任务
 * @param id
 * @param assigneeUserId
 * @param reason
 */
export const transferTask = (id, assigneeUserId, reason) =>
  request({
    url: '/bpm/task/transfer',
    method: 'PUT',
    data: { id, assigneeUserId, reason },
  })

/**
 * 委派任务
 * @param id
 * @param delegateUserId
 * @param reason
 */
export const delegateTask = (id, delegateUserId, reason) =>
  request({
    url: '/bpm/task/delegate',
    method: 'PUT',
    data: { id, delegateUserId, reason }
  })

/**
 * 加签任务
 * @param id
 * @param userIds
 * @param type before/after
 * @param reason
 */
export const createSignTask = (id, userIds, type, reason) =>
  request({
    url: '/bpm/task/create-sign',
    method: 'PUT',
    data: { id, userIds, type, reason },
  })

/**
 * 退回任务
 * @param id
 */
export const returnTask = (id) =>
  request({
    url: '/bpm/task/list-by-return',
    method: 'GET',
    params: { id },
  })

/**
 * 取消任务
 * @param id
 * @param reason
 */
export const cancelTask = (id, reason) =>
  request({
    url: '/bpm/process-instance/cancel-by-start-user',
    method: 'DELETE',
    data: { id, reason },
  })

/**
 * 获取超时消息
 * @param params
 */
export const getOvertimeTaskList = (params) =>
  request({
    url: '/rq/stat/notice',
    method: 'GET',
    params,
  })