import request from '@/utils/request'
import { AxiosPromise } from 'axios'

// apiUrl
const api = {
	pagePendingClaim: '/v1/process-task/page-pending-claim',
	pagePendingApproval: '/v1/process-task/page-pending-approval',
	pageMyReceived: '/v1/process-task/page-my-received',
	pageMyApplication: '/v1/process-task/page-my-application',
	pageApproved: '/v1/process-task/page-approved',
	listHisTask: '/v1/process-task/list-his-task', // todo废弃了
	consentTask: '/v1/process-task/consent', // 审批同意
	rejectionTask: '/v1/process-task/rejection', // 审批拒绝
	reviewTask: '/v1/process-task/comment', // 评论审批
	appendNode: '/v1/process-task/append-node', // 加签审批
	transfer: '/v1/process-task/transfer', // 转交任务
	claimProcess: '/v1/process-task/claim', // 认领任务
	revokeProcess: '/v1/process-task/revoke', // 撤回任务
	previousNodeName: '/v1/process-task/previous-node-names', // 以前节点名称列表
	processTaskJump: '/v1/process-task/jump', // 跳到指定节点任务
	countTask: '/v1/process-task/count-pending-approval' // 我的待办数量
}

// 待认领任务分页列表
export function processTaskPagePendingClaimApi(data: any): AxiosPromise {
	return request({
		url: api.pagePendingClaim,
		method: 'post',
		data
	})
}

// 待审批任务分页列表
export function processTaskPagePendingApprovalApi(data: any): AxiosPromise {
	return request({
		url: api.pagePendingApproval,
		method: 'post',
		data
	})
}

// 我收到的任务分页列表
export function processTaskPageMyReceivedApi(data: any): AxiosPromise {
	return request({
		url: api.pageMyReceived,
		method: 'post',
		data
	})
}

// 我的申请任务分页列表
export function processTaskPageMyApplicationApi(data: any): AxiosPromise {
	return request({
		url: api.pageMyApplication,
		method: 'post',
		data
	})
}

// 已审批任务分页列表
export function processTaskPageApprovedApi(data: any): AxiosPromise {
	return request({
		url: api.pageApproved,
		method: 'post',
		data
	})
}

// todo废弃了
export function processTaskListHisTaskApi(instanceId: string): AxiosPromise {
	return request({
		url: `${api.listHisTask}/${instanceId}`,
		method: 'post'
	})
}

// 审批同意
export function processConsentTaskApi(data: any): AxiosPromise {
	return request({
		url: api.consentTask,
		method: 'post',
		data
	})
}

// 审批拒绝
export function processRejectionTaskApi(data: any): AxiosPromise {
	return request({
		url: api.rejectionTask,
		method: 'post',
		data
	})
}

// 评论审批
export function processReviewTaskApi(data: any): AxiosPromise {
	return request({
		url: api.reviewTask,
		method: 'post',
		data
	})
}

// 加签审批
export function processAppendNodeApi(data: any): AxiosPromise {
	return request({
		url: api.appendNode,
		method: 'post',
		data
	})
}

// 转交审批
export function processTransferApi(data: any): AxiosPromise {
	return request({
		url: api.transfer,
		method: 'post',
		data
	})
}

// 查看审批信息
export function processTaskApprovalInfo(data: any): AxiosPromise {
	return request({
		url: `/v1/process-task/approval-info`,
		method: 'post',
		data
	})
}

// 认领任务
export function processClaimTaskApi(taskId: string): AxiosPromise {
	return request({
		url: `${api.claimProcess}-${taskId}`,
		method: 'post'
	})
}

// 撤回任务
export function processRevokeTaskApi(data: any): AxiosPromise {
	return request({
		url: `${api.revokeProcess}`,
		method: 'post',
		data
	})
}

// 以前节点名称列表
export function processPreviousNodeNameApi(taskId: string): AxiosPromise {
	return request({
		url: `${api.previousNodeName}/${taskId}`,
		method: 'post'
	})
}

// 跳到指定节点任务
export function processTaskJumpApi(data: any): AxiosPromise {
	return request({
		url: `${api.processTaskJump}`,
		method: 'post',
		data
	})
}

// 待办数量
export function countTaskApi(): AxiosPromise {
	return request({
		url: api.countTask,
		method: 'post'
	})
}

export default {
	processTaskPageMyApplicationApi,
	processTaskPageApprovedApi,
	processTaskListHisTaskApi,
	processConsentTaskApi,
	processRejectionTaskApi,
	processReviewTaskApi,
	processTaskApprovalInfo,
	processAppendNodeApi,
	processTransferApi,
	processClaimTaskApi,
	processRevokeTaskApi,
	processPreviousNodeNameApi,
	processTaskJumpApi,
	countTaskApi
}
