import { PAGE_MESSAGE_LIST, PAGE_MESSAGE_DETAIL, PAGE_ENTRY_DETAIL } from '@/utils/pageRoute'
import { MESSAGE_LINK_MERCHANT_ENTRY } from '@/constants/message'

/** 消息列表 */
export function goMessageList() {
  uni.navigateTo({ url: PAGE_MESSAGE_LIST })
}

/** 消息详情 */
export function goMessageDetail(messageId) {
  if (!messageId) return
  uni.navigateTo({
    url: `${PAGE_MESSAGE_DETAIL}?messageId=${messageId}`
  })
}

/** 按 linkType 跳转关联业务 */
export function goMessageLink(detail) {
  if (!detail || !detail.linkAvailable) {
    uni.showToast({ title: '关联内容不存在', icon: 'none' })
    return
  }
  if (detail.linkType === MESSAGE_LINK_MERCHANT_ENTRY && detail.bizId) {
    uni.navigateTo({
      url: `${PAGE_ENTRY_DETAIL}?applyId=${detail.bizId}`
    })
    return
  }
  uni.showToast({ title: '暂不支持跳转', icon: 'none' })
}
