import request from '@/utils/request'

const api = {
  unreadCount: '/notifies/unread_count',
  notifies: '/notifies',
  readNotice: '/notifies/mark_as_read/{noticeId}',
  readAllNotices: '/notifies/mark_as_read_all',
  sendMessage: '/notifies/send/{orderId}'
}
// 未读消息总数 6s 一轮回
export function getUnreadCount () {
  return request({
    url: api.unreadCount,
    method: 'get'
  })
}

// 消息列表
export function getNoticeList (parameter) {
  return request({
    url: api.notifies,
    method: 'get',
    params: parameter
  })
}

// 消息已读
export function readNotice (noticeId) {
  return request({
    url: api.readNotice.replace('{noticeId}', noticeId),
    method: 'POST'
  })
}

// 消息全部已读
export function readAllNotice (noticeId) {
  return request({
    url: api.readAllNotices,
    method: 'POST'
  })
}

// 发送消息

export function sendMessage (orderId, type, itemId) {
  return request({
    url: api.sendMessage.replace('{orderId}', orderId),
    method: 'POST',
    params: {
      type: type,
      item_id: itemId
    }
  })
}
