/**
 * 消息接口
 */
import { request } from '../../utils/request'

/**
 * 获取消息列表
 * @param pageNum 页码
 * @param pageSize 每页数量
 * @param keyword 关键字
 * @param status 状态 UNREAD未读，READ已读
 * @returns 
 */
export const getMessageList = (pageNum: number, pageSize: number, keyword: string, status: string): Promise<any> => {
	let url = `/system/message/unprocessedList?pageNum=${pageNum}&pageSize=${pageSize}`
	if (keyword != null && keyword.length > 0) {
		url += `&messageContent=${encodeURIComponent(keyword)}`
	}
	if (status != null && status.length > 0) {
		url += `&status=${status}`
	}
	return request({
		url: url,
		method: 'GET'
	})
}

/**
 * 获取未处理消息列表
 * @param pageNum 页码
 * @param pageSize 每页数量
 * @param keyword 关键字
 * @returns 
 */
export const getUnprocessedMessageList = (pageNum: number, pageSize: number, keyword: string): Promise<any> => {
	let url = `/system/message/unprocessedList?pageNum=${pageNum}&pageSize=${pageSize}`
	if (keyword != null && keyword.length > 0) {
		url += `&messageTitle=${encodeURIComponent(keyword)}`
	}
	return request({
		url: url,
		method: 'GET'
	})
}

/**
 * 标记消息为已读
 * @param messageId 消息ID
 * @returns 
 */
export const markMessageAsRead = (messageId: string): Promise<any> => {
	return request({
		url: `/system/message/read`,
		method: 'PUT',
		data: {
			messageId: messageId
		}
	})
}

/**
 * 删除消息
 * @param messageId 消息ID
 * @returns 
 */
export const deleteMessage = (messageId: string): Promise<any> => {
	return request({
		url: `/system/message/${messageId}`,
		method: 'DELETE'
	})
}
