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

// apiUrl
const api = {
	create: '/v1/process/create', // 新增创建流程
	delete: '/v1/process/delete', // 删除流程
	listCategory: '/v1/process/list-category', // 流程分类定义列表列表
	clone: '/v1/process/clone', // 复制流程
	updateProcessState: 'v1/process/update-state', // 更新流程状态
	detailProcess: '/v1/process/get', // 流程详情
	launchProcessList: '/v1/process/list-launch', // 发起审批流程列表
	releaseProcess: '/v1/process/release', // 发布流程
	processListNodeMap: '/v1/process/list-node-map', // 根据 id 获取节点 map 列表
	processNodeModel: '/v1/process/node-model', // 根据 id 获取模型
	processLaunch: '/v1/process/launch' // 发起流程
}

function progressCreateApi(data: any): AxiosPromise {
	return request({
		url: api.create,
		method: 'post',
		data
	})
}

function progressDeleteApi(data: any): AxiosPromise {
	return request({
		url: api.delete + '?id=' + data.id,
		method: 'post'
	})
}
function progressListCategoryApi(data: any): AxiosPromise {
	return request({
		url: api.listCategory,
		method: 'post',
		data
	})
}

function launchProcessListApi(data: any): AxiosPromise {
	return request({
		url: api.launchProcessList,
		method: 'post',
		data
	})
}

function releaseProcessApi(data: any): AxiosPromise {
	return request({
		url: `${api.releaseProcess}?id=${data.id}`,
		method: 'post'
	})
}

function processListNodeMapApi(id: string): AxiosPromise {
	return request({
		url: `${api.processListNodeMap}?id=${id}`,
		method: 'post'
	})
}
// 有问题 不再使用
function processNodeModelApi(id: string): AxiosPromise {
	return request({
		url: `${api.processNodeModel}?id=${id}`,
		method: 'post'
	})
}

function processLaunchApi(data): AxiosPromise {
	return request({
		url: api.processLaunch,
		method: 'post',
		data
	})
}

function progressCloneApi(data: any): AxiosPromise {
	return request({
		url: api.clone + '?id=' + data.id,
		method: 'get'
	})
}
function processUpdateStateApi(data: any): AxiosPromise {
	return request({
		url: `${api.updateProcessState}-${data.id}` + '?state=' + data.state,
		method: 'post'
	})
}

function processDetailApi(id: any): AxiosPromise {
	return request({
		url: `${api.detailProcess}?id=${id}`,
		method: 'get'
	})
}

export default {
	progressCreateApi,
	progressDeleteApi,
	progressListCategoryApi,
	processListNodeMapApi,
	processNodeModelApi,
	processLaunchApi,
	progressCloneApi,
	processUpdateStateApi,
	processDetailApi,
	launchProcessListApi,
	releaseProcessApi
}
