import request from '@/utils/request'

export default {
	// 系统配置管理
	config: {
		list: {
			get: async function (params) {
				return await request.get('system/setting', { params })
			},
		},
		groups: {
			get: async function () {
				return await request.get('system/setting/groups')
			},
		},
		all: {
			get: async function (params) {
				return await request.get('system/setting/all', { params })
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`system/setting/${id}`)
			},
		},
		add: {
			post: async function (params) {
				return await request.post('system/setting', params)
			},
		},
		edit: {
			put: async function (id, params) {
				return await request.put(`system/setting/${id}`, params)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`system/setting/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('system/setting/batch-delete', params)
			},
		},
		batchStatus: {
			post: async function (params) {
				return await request.post('system/setting/batch-status', params)
			},
		},
	},

	// 操作日志管理
	log: {
		list: {
			get: async function (params) {
				return await request.get('system/log', { params })
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`system/log/${id}`)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`system/log/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('system/log/batch-delete', params)
			},
		},
		clear: {
			post: async function (params) {
				return await request.post('system/log/clear', params)
			},
		},
		export: {
			get: async function (params) {
				return await request.get('system/log/export', {
					params,
					responseType: 'blob',
				})
			},
		},
		statistics: {
			get: async function (params) {
				return await request.get('system/log/statistics', { params })
			},
		},
	},

	// 数据字典管理
	dictionary: {
		list: {
			get: async function (params) {
				return await request.get('system/dictionary', { params })
			},
		},
		all: {
			get: async function () {
				return await request.get('system/dictionary/all')
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`system/dictionary/${id}`)
			},
		},
		add: {
			post: async function (params) {
				return await request.post('system/dictionary', params)
			},
		},
		edit: {
			put: async function (id, params) {
				return await request.put(`system/dictionary/${id}`, params)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`system/dictionary/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('system/dictionary/batch-delete', params)
			},
		},
		batchStatus: {
			post: async function (params) {
				return await request.post('system/dictionary/batch-status', params)
			},
		},
		items: {
			all: {
				get: async function (code) {
					return await request.get(`system/dictionary/code`, {
						params: { code },
					})
				},
			},
		},
	},

	// 数据字典项管理
	dictionaryItem: {
		list: {
			get: async function (params) {
				return await request.get('system/dictionary-item', { params })
			},
		},
		all: {
			get: async function () {
				return await request.get('system/dictionary-item/all')
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`system/dictionary-item/${id}`)
			},
		},
		add: {
			post: async function (params) {
				return await request.post('system/dictionary-item', params)
			},
		},
		edit: {
			put: async function (id, params) {
				return await request.put(`system/dictionary-item/${id}`, params)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`system/dictionary-item/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('system/dictionary-item/batch-delete', params)
			},
		},
		batchStatus: {
			post: async function (params) {
				return await request.post('system/dictionary-item/batch-status', params)
			},
		},
	},

	// 任务管理
	task: {
		list: {
			get: async function (params) {
				return await request.get('system/task', { params })
			},
		},
		all: {
			get: async function () {
				return await request.get('system/task/all')
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`system/task/${id}`)
			},
		},
		add: {
			post: async function (params) {
				return await request.post('system/task', params)
			},
		},
		edit: {
			put: async function (id, params) {
				return await request.put(`system/task/${id}`, params)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`system/task/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('system/task/batch-delete', params)
			},
		},
		batchStatus: {
			post: async function (params) {
				return await request.post('system/task/batch-status', params)
			},
		},
		run: {
			post: async function (id) {
				return await request.post(`system/task/${id}/run`)
			},
		},
		statistics: {
			get: async function () {
				return await request.get('system/task/statistics')
			},
		},
	},

	// 城市数据管理
	city: {
		list: {
			get: async function (params) {
				return await request.get('system/city', { params })
			},
		},
		tree: {
			get: async function () {
				return await request.get('system/city/tree')
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`system/city/${id}`)
			},
		},
		children: {
			get: async function (code) {
				return await request.get(`system/city/code/${code}/children`)
			},
		},
		provinces: {
			get: async function () {
				return await request.get('system/city/provinces')
			},
		},
		cities: {
			get: async function (provinceId) {
				return await request.get(`system/city/${provinceId}/cities`)
			},
		},
		districts: {
			get: async function (cityId) {
				return await request.get(`system/city/${cityId}/districts`)
			},
		},
		add: {
			post: async function (params) {
				return await request.post('system/city', params)
			},
		},
		edit: {
			put: async function (id, params) {
				return await request.put(`system/city/${id}`, params)
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`system/city/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('system/city/batch-delete', params)
			},
		},
		batchStatus: {
			post: async function (params) {
				return await request.post('system/city/batch-status', params)
			},
		},
	},

	// 文件上传管理
	upload: {
		single: {
			post: async function (formData) {
				return await request.post('system/upload', formData, {
					headers: { 'Content-Type': 'multipart/form-data' },
				})
			},
		},
		multiple: {
			post: async function (formData) {
				return await request.post('system/upload/multiple', formData, {
					headers: { 'Content-Type': 'multipart/form-data' },
				})
			},
		},
		base64: {
			post: async function (params) {
				return await request.post('system/upload/base64', params)
			},
		},
		delete: {
			post: async function (params) {
				return await request.post('system/upload/delete', params)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('system/upload/batch-delete', params)
			},
		},
	},

	// 通知管理
	notification: {
		list: {
			get: async function (params) {
				return await request.get('system/notification', { params })
			},
		},
		unread: {
			get: async function (params) {
				return await request.get('system/notification/unread', {
					params,
				})
			},
		},
		unreadCount: {
			get: async function () {
				return await request.get('system/notification/unread-count')
			},
		},
		detail: {
			get: async function (id) {
				return await request.get(`system/notification/${id}`)
			},
		},
		markAsRead: {
			post: async function (id) {
				return await request.post(`system/notification/${id}/read`)
			},
		},
		batchMarkAsRead: {
			post: async function (params) {
				return await request.post('system/notification/batch-read', params)
			},
		},
		markAllAsRead: {
			post: async function () {
				return await request.post('system/notification/read-all')
			},
		},
		delete: {
			delete: async function (id) {
				return await request.delete(`system/notification/${id}`)
			},
		},
		batchDelete: {
			post: async function (params) {
				return await request.post('system/notification/batch-delete', params)
			},
		},
		clearRead: {
			post: async function () {
				return await request.post('system/notification/clear-read')
			},
		},
		statistics: {
			get: async function () {
				return await request.get('system/notification/statistics')
			},
		},
		send: {
			post: async function (params) {
				return await request.post('system/notification/send', params)
			},
		},
		retryUnsent: {
			post: async function (params) {
				return await request.post('system/notification/retry-unsent', params)
			},
		},
	},

	// 公共接口 (无需认证)
	public: {
		config: {
			all: {
				get: async function () {
					return await request.get('system/config')
				},
			},
			group: {
				get: async function (params) {
					return await request.get('system/config/group', {
						params,
					})
				},
			},
			key: {
				get: async function (params) {
					return await request.get('system/config/key', { params })
				},
			},
		},
		dictionary: {
			all: {
				get: async function () {
					return await request.get('system/dictionary')
				},
			},
			code: {
				get: async function (params) {
					return await request.get('system/dictionary/code', {
						params,
					})
				},
			},
			detail: {
				get: async function (id) {
					return await request.get(`system/dictionary/${id}`)
				},
			},
		},
		city: {
			tree: {
				get: async function () {
					return await request.get('system/city/tree')
				},
			},
			provinces: {
				get: async function () {
					return await request.get('system/city/provinces')
				},
			},
			cities: {
				get: async function (provinceId) {
					return await request.get(`system/city/${provinceId}/cities`)
				},
			},
			districts: {
				get: async function (cityId) {
					return await request.get(`system/city/${cityId}/districts`)
				},
			},
			detail: {
				get: async function (id) {
					return await request.get(`system/city/${id}`)
				},
			},
		},
		upload: {
			post: async function (formData) {
				return await request.post('system/upload', formData, {
					headers: { 'Content-Type': 'multipart/form-data' },
				})
			},
		},
	},
}
