import HttpAxios from '@/utils/axios'

const base = import.meta.env.VITE_API_HOST
const baseUrl = `${base}/main_new_version.php`

/**
 * 保存用户个人信息或日期和数字格式化配置
 * @param save_model profile 代表基本信息的save, no_profile 代表格式信息的save
 * @param first_name
 * @param last_name
 * @param date_fromat
 * @param numbers_format
 */
export const saveUserInfo = (params: any) => {
  return HttpAxios.post(`${baseUrl}`, {
    action: 'system_setting',
    operate: 'personal_profile_save',
    ...params
  })
}

/**
 * 获取notification消息列表
 * @param rules_type 特定类型的消息，all查全部
 * @param current_time 当前时间 轮询查询时使用
 */
export const getNotificationList = (params: any) => {
  return HttpAxios.get(`${baseUrl}`, {
    action: 'notifications_rules',
    operate: 'notifications_init',
    ...params
  })
}

/**
 * 获取notification消息的see all详情
 */
export const getNotificationDetails = (params: any) => {
  return HttpAxios.post(`${baseUrl}`, {
    action: 'notifications_rules',
    operate: 'notifications_see_all',
    ...params
  })
}

/**
 * 获取system message页面数据
 */
export const getSystemMessageData = (params: any) => {
  return HttpAxios.get(`${baseUrl}`, {
    action: 'notifications_rules',
    operate: 'notifications_message_init',
    ...params
  })
}

/**
 * 将notification消息标记为已读
 * @param id 消息id Array
 * @param read_type 如果标记全部为已读 = true. 否则其他情况为false
 */
export const setMessageRead = (params: any) => {
  return HttpAxios.post(`${baseUrl}`, {
    action: 'notifications_rules',
    operate: 'notifications_read',
    read_type: false,
    ...params
  })
}

/**
 * 检测是否有新消息
 */
export const hasUnreadMessages = () => {
  return HttpAxios.post(`${baseUrl}`, {
    action: 'notifications_rules',
    operate: 'check_notifications_message'
  })
}

/**
 * 获取feature message详情数据
 */
export const getFeatureMsgPdf = () => {
  return HttpAxios.get(`${baseUrl}`, {
    action: 'feature_update'
  })
}
