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

// apiUrl
const api = {
	page: '/sys/role/page',
	listTree: '/sys/role/list-tree',
	listAll: '/sys/role/list-all',
	create: '/sys/role/create',
	update: '/sys/role/update',
	delete: '/sys/role/delete',
	resourceSet: '/sys/role/resource-set',
	resourceIds: '/sys/role/resource-ids'
}

const role = {
	rolePageApi: (data): AxiosPromise =>
		request({
			url: api.page,
			method: 'post',
			data
		}),
	roleListTreeApi: (): AxiosPromise => request({ url: api.listTree, method: 'get' }),
	roleListAllApi: (): AxiosPromise => request({ url: api.listAll, method: 'get' }),
	roleSaveApi: (data): AxiosPromise => request({ url: data.id ? api.update : api.create, method: 'post', data }),
	roleDeleteApi: (data): AxiosPromise => request({ url: api.delete, method: 'post', data }),
	roleResourceSetApi: (data): AxiosPromise => request({ url: api.resourceSet, method: 'post', data }),
	roleResourceIdsApi: (id): AxiosPromise => request({ url: api.resourceIds + '?id=' + id, method: 'get' })
}
export default role
