import { get, post, put } from './request'

// ==================== 通知公告 API（后台 /notice）====================
export function getNoticeList(pageNum = 1, pageSize = 10, type?: string) {
  return get('/notice/list', { pageNum, pageSize, type })
}

export function getNoticeDetail(noticeId: number) {
  return get(`/notice/${noticeId}`)
}

// ==================== 消息通知 API（后台 /message）====================
export interface Message {
  messageId?: number
  title: string
  content: string
  messageType?: string
  type?: string
  receiverId?: number
  senderId?: number
  senderName?: string
  isRead?: number
  readStatus?: number
  createTime?: string
  extraData?: string
}

export function getMessageList(pageNum = 1, pageSize = 10, type?: string) {
  const params: Record<string, any> = { pageNum, pageSize }
  if (type && type !== 'all') {
    params.type = type
  }
  return get<{ rows: Message[]; total: number }>('/message/list', params)
}

export function getMessageDetail(messageId: number) {
  return get<Message>(`/message/${messageId}`)
}

export function markMessageRead(messageId: number) {
  return post(`/message/read/${messageId}`, {})
}

export function markAllMessageRead() {
  return post('/message/read-all', {})
}

export function getUnreadMessageCount() {
  return get<number>('/message/unread-count')
}

export function sendMessage(data: Message) {
  return post('/message/send', data)
}
