import request from '@/utils/request'

export default {
	// 认证相关
	login: {
		post: async function (params) {
			return await request.post('auth/login', params)
		},
	},
	logout: {
		post: async function () {
			return await request.post('auth/logout')
		},
	},
	me: {
		get: async function () {
			return await request.get('auth/me')
		},
	},
	changePassword: {
		post: async function (params) {
			return await request.post('auth/change-password', params)
		},
	},

	// 文件上传
	upload: {
		post: async function (file) {
			const formData = new FormData()
			formData.append('file', file)
			return await request.post('system/upload', formData, {
				headers: { 'Content-Type': 'multipart/form-data' },
			})
		},
	},

	// 用户管理
	user: {
		list: {
			get: async function (params) {
				return await request.get('auth/user', { params })
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`auth/user/${id}`)
			},
		},
		add: {
			post: async function (params) {
				return await request.post('auth/user', params)
			},
		},
		edit: {
			put: async function (id, params) {
				return await request.put(`auth/user/${id}`, params)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`auth/user/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('auth/user/batch-delete', params)
			},
		},
		batchStatus: {
			post: async function (params) {
				return await request.post('auth/user/batch-status', params)
			},
		},
		batchDepartment: {
			post: async function (params) {
				return await request.post('auth/user/batch-department', params)
			},
		},
		batchRoles: {
			post: async function (params) {
				return await request.post('auth/user/batch-roles', params)
			},
		},
		export: {
			post: async function (params) {
				return await request.post('auth/user/export', params, {
					responseType: 'blob',
				})
			},
		},
		import: {
			post: async function (formData) {
				return await request.post('auth/user/import', formData, {
					headers: { 'Content-Type': 'multipart/form-data' },
				})
			},
		},
		downloadTemplate: {
			get: async function () {
				return await request.get('auth/user/download-template', {
					responseType: 'blob',
				})
			},
		},
	},

	// 在线用户管理
	onlineUser: {
		count: {
			get: async function () {
				return await request.get('auth/online-user/count')
			},
		},
		list: {
			get: async function (params) {
				return await request.get('auth/online-user', { params })
			},
		},
		sessions: {
			get: async function (userId) {
				return await request.get(`auth/online-user/${userId}/sessions`)
			},
		},
		offline: {
			post: async function (userId, params) {
				return await request.post(`auth/online-user/${userId}/offline`, params)
			},
		},
		offlineAll: {
			post: async function (userId) {
				return await request.post(`auth/online-user/${userId}/offline-all`)
			},
		},
	},

	// 角色管理
	role: {
		list: {
			get: async function (params) {
				return await request.get('auth/role', { params })
			},
		},
		all: {
			get: async function () {
				return await request.get('auth/role/all')
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`auth/role/${id}`)
			},
		},
		add: {
			post: async function (params) {
				return await request.post('auth/role', params)
			},
		},
		edit: {
			put: async function (id, params) {
				return await request.put(`auth/role/${id}`, params)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`auth/role/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('auth/role/batch-delete', params)
			},
		},
		batchStatus: {
			post: async function (params) {
				return await request.post('auth/role/batch-status', params)
			},
		},
		permissions: {
			get: async function (id) {
				return await request.get(`auth/role/${id}/permissions`)
			},
			post: async function (id, params) {
				return await request.post(`auth/role/${id}/permissions`, params)
			},
		},
		copy: {
			post: async function (id, params) {
				return await request.post(`auth/role/${id}/copy`, params)
			},
		},
		batchCopy: {
			post: async function (params) {
				return await request.post('auth/role/batch-copy', params)
			},
		},
		export: {
			post: async function (params) {
				return await request.post('auth/role/export', params, {
					responseType: 'blob',
				})
			},
		},
		import: {
			post: async function (formData) {
				return await request.post('auth/role/import', formData, {
					headers: { 'Content-Type': 'multipart/form-data' },
				})
			},
		},
		downloadTemplate: {
			get: async function () {
				return await request.get('auth/role/download-template', {
					responseType: 'blob',
				})
			},
		},
	},

	// 权限管理
	permission: {
		list: {
			get: async function (params) {
				return await request.get('auth/permission', { params })
			},
		},
		tree: {
			get: async function () {
				return await request.get('auth/permission/tree')
			},
		},
		menu: {
			get: async function () {
				return await request.get('auth/permission/menu')
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`auth/permission/${id}`)
			},
		},
		add: {
			post: async function (params) {
				return await request.post('auth/permission', params)
			},
		},
		edit: {
			put: async function (id, params) {
				return await request.put(`auth/permission/${id}`, params)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`auth/permission/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('auth/permission/batch-delete', params)
			},
		},
		batchStatus: {
			post: async function (params) {
				return await request.post('auth/permission/batch-status', params)
			},
		},
		export: {
			post: async function (params) {
				return await request.post('auth/permission/export', params, {
					responseType: 'blob',
				})
			},
		},
		import: {
			post: async function (formData) {
				return await request.post('auth/permission/import', formData, {
					headers: { 'Content-Type': 'multipart/form-data' },
				})
			},
		},
		downloadTemplate: {
			get: async function () {
				return await request.get('auth/permission/download-template', {
					responseType: 'blob',
				})
			},
		},
	},

	// 部门管理
	department: {
		list: {
			get: async function (params) {
				return await request.get('auth/department', { params })
			},
		},
		tree: {
			get: async function (params) {
				return await request.get('auth/department/tree', { params })
			},
		},
		all: {
			get: async function () {
				return await request.get('auth/department/all')
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`auth/department/${id}`)
			},
		},
		add: {
			post: async function (params) {
				return await request.post('auth/department', params)
			},
		},
		edit: {
			put: async function (id, params) {
				return await request.put(`auth/department/${id}`, params)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`auth/department/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('auth/department/batch-delete', params)
			},
		},
		batchStatus: {
			post: async function (params) {
				return await request.post('auth/department/batch-status', params)
			},
		},
		export: {
			post: async function (params) {
				return await request.post('auth/department/export', params, {
					responseType: 'blob',
				})
			},
		},
		import: {
			post: async function (formData) {
				return await request.post('auth/department/import', formData, {
					headers: { 'Content-Type': 'multipart/form-data' },
				})
			},
		},
		downloadTemplate: {
			get: async function () {
				return await request.get('auth/department/download-template', {
					responseType: 'blob',
				})
			},
		},
	},
}
