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' // 流程详情
}

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 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: 'get'
	})
}

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

export default {
	progressCreateApi,
	progressDeleteApi,
	progressListCategoryApi,
	progressCloneApi,
	processUpdateStateApi,
	processDetailApi
}
