import request from '@/utils/request'

// ========================================
// 系统通知相关API（用于 /system/message 页面）
// ========================================

// 查询系统通知列表（管理员）
export function listNotification(query) {
  return request({
    url: '/system/notification/list',
    method: 'get',
    params: query
  })
}

// 获取系统通知详细信息
export function getNotification(notificationId) {
  return request({
    url: '/system/notification/' + notificationId,
    method: 'get'
  })
}

// 新增系统通知
export function addNotification(data) {
  return request({
    url: '/system/notification',
    method: 'post',
    data: data
  })
}

// 修改系统通知
export function updateNotification(data) {
  return request({
    url: '/system/notification',
    method: 'put',
    data: data
  })
}

// 删除系统通知
export function delNotification(notificationId) {
  return request({
    url: '/system/notification/' + notificationId,
    method: 'delete'
  })
}

// 发布通知
export function publishNotification(notificationId) {
  return request({
    url: '/system/notification/' + notificationId + '/publish',
    method: 'post'
  })
}

// 获取用户通知列表
export function getMyNotifications() {
  return request({
    url: '/system/notification/my',
    method: 'get'
  })
}

// 获取未读通知数量
export function getUnreadNotificationCount() {
  return request({
    url: '/system/notification/unread/count',
    method: 'get'
  })
}

// 标记通知为已读
export function markNotificationAsRead(notificationId) {
  return request({
    url: '/system/notification/' + notificationId + '/read',
    method: 'put'
  })
}

// 删除用户通知
export function deleteMyNotification(notificationId) {
  return request({
    url: '/system/notification/' + notificationId + '/my',
    method: 'delete'
  })
}

// ========================================
// 用户对话相关API（用于 /message 页面）
// ========================================

// 获取会话列表
export function getConversationList() {
  return request({
    url: '/chat/conversations',
    method: 'get'
  })
}

// 创建或获取私聊会话
export function createPrivateConversation(otherUserId) {
  return request({
    url: '/chat/conversation/private/' + otherUserId,
    method: 'post'
  })
}

// 获取会话消息列表
export function getConversationMessages(conversationId, pageNum = 1, pageSize = 50) {
  return request({
    url: '/chat/conversation/' + conversationId + '/messages',
    method: 'get',
    params: { pageNum, pageSize }
  })
}

// 发送消息
export function sendMessage(conversationId, content) {
  return request({
    url: '/chat/conversation/' + conversationId + '/message',
    method: 'post',
    data: { content }
  })
}

// 设置会话备注
export function setConversationRemark(conversationId, remarkName) {
  return request({
    url: '/chat/conversation/' + conversationId + '/remark',
    method: 'put',
    data: { remarkName }
  })
}

// 获取会话未读消息数
export function getConversationUnreadCount(conversationId) {
  return request({
    url: '/chat/conversation/' + conversationId + '/unread',
    method: 'get'
  })
}

// 标记会话为已读
export function markConversationAsRead(conversationId) {
  return request({
    url: '/chat/conversation/' + conversationId + '/read',
    method: 'put'
  })
}

// 删除会话
export function deleteConversation(conversationId) {
  return request({
    url: '/chat/conversation/' + conversationId,
    method: 'delete'
  })
}
