import request from './request'

/**
 * 消息相关 API
 */

/**
 * 获取消息列表
 * @param {Object} params - 查询参数
 * @param {number} [params.pageIndex] - 页码
 * @param {number} [params.pageSize] - 每页数量
 * @returns {Promise<{success: boolean, data: Array, total: number}>}
 */
export const getMessageList = (params = {}) => {
  return request({
    url: '/MessageRecord/GetList',
    method: 'get',
    params
  })
}

/**
 * 获取未读消息数量
 * @returns {Promise<{success: boolean, data: number}>}
 */
export const getUnreadCount = () => {
  return request({
    url: '/MessageRecord/GetUnreadCount',
    method: 'get'
  })
}

/**
 * 标记消息为已读
 * @param {number} id - 消息ID
 * @returns {Promise<{success: boolean}>}
 */
export const markAsRead = (id) => {
  return request({
    url: '/MessageRecord/MarkAsRead',
    method: 'post',
    params: { id }
  })
}

/**
 * 全部标记为已读
 * @returns {Promise<{success: boolean}>}
 */
export const markAllAsRead = () => {
  return request({
    url: '/MessageRecord/MarkAllAsRead',
    method: 'post'
  })
}

/**
 * 删除消息
 * @param {number} id - 消息ID
 * @returns {Promise<{success: boolean}>}
 */
export const deleteMessage = (id) => {
  return request({
    url: '/MessageRecord/Delete',
    method: 'post',
    params: { id }
  })
}

/**
 * 新增消息 (测试用)
 * @param {Object} data - 消息数据
 * @returns {Promise<{success: boolean}>}
 */
export const addMessage = (data) => {
  return request({
    url: '/MessageRecord/Add',
    method: 'post',
    data
  })
}
