import Request from '../..'

// 查询用户公告
export function getUserMessagePage(query: API.PageParams) {
  return Request.get<API.TableListResult<API.UserMessagePageResult>>({
    url: '/cms/message/user/page',
    params: query
  })
}

// 查询信息阅读列表
export function getMessageReadPage(query: API.PageParams) {
  return Request.get<API.TableListResult<API.MessageReadPageResult>>({
    url: '/cms/message/user/read/page',
    params: query
  })
}

// 站内信分页
export function getMessagePage(query: API.PageParams<{ title?: string }>) {
  return Request.get<API.TableListResult<API.MessageReadPageResult>>({
    url: '/cms/message/page',
    params: query
  })
}

// 新增站内信
export function addMessage(data: API.AddMessageParam) {
  return Request.post({
    url: '/cms/message/create',
    data
  })
}

// 修改站内信
export function updateMessage(data: API.UpdateMessageParam) {
  return Request.post({
    url: '/cms/message/update',
    data
  })
}

// 删除站内信
export function delMessage(msgId: number | string) {
  return Request.post({
    url: '/cms/message/del',
    data: { msgIds: [msgId], deleteType: 'SOFT' }
  })
}

// 通过ID查询站内信息
export function getMessageDetail(msg_id: string | number) {
  return Request.get({
    url: `/cms/message/${msg_id}`
  })
}

// 发送站内信
export function sendMessage(msgId: number | string) {
  return Request.post({
    url: `/cms/message/send/${msgId}`
  })
}

// 读取站内信
export function readMessage(msgId: number | string) {
  return Request.post({
    url: `/cms/message/read/${msgId}`
  })
}
