import axios from 'bc-common-ui-vue3/src/bc-components/bc-libs/api.request'

import { TOKEN_KEY } from 'bc-common-ui-vue3/src/bc-components/bc-libs/util'

export const login = ({ username, password, ukeyId }) => {
  const data = {
    username,
    password,
    ukeyId: ukeyId,
    grant_type: 'password',
    client_id: 'csbckj2',
    client_secret: 'csbckj',
  }
  return axios.request({
    url: 'cas/oauth/token',
    params: data,
    method: 'post',
  })
}

export const getUserInfo = (token) => {
  let params = {}
  /*params[TOKEN_KEY] = token;*/
  return axios.request({
    //url: 'rbac/auth/getUserByToken',
    url: 'cas/user/',
    params: params,
    method: 'get',
  })
}

export const logout = (token) => {
  const data = {
    grant_type: 'password',
    client_id: 'csbckj2',
    client_secret: 'csbckj',
  }
  return axios.request({
    url: 'cas/oauth/revokeToken',
    data: data,
    method: 'post',
  })
}

export const getUnreadCount = () => {
  return axios.request({
    url: 'api/v1/message/count',
    method: 'get',
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'api/v1/message/init',
    method: 'get',
  })
}

export const getContentByMsgId = (msg_id) => {
  return axios.request({
    url: 'api/v1/message/content',
    method: 'get',
    params: {
      msg_id,
    },
  })
}

export const hasRead = (msg_id) => {
  return axios.request({
    url: 'api/v1/message/has_read',
    method: 'post',
    data: {
      msg_id,
    },
  })
}

export const removeReaded = (msg_id) => {
  return axios.request({
    url: 'api/v1/message/remove_readed',
    method: 'post',
    data: {
      msg_id,
    },
  })
}

export const restoreTrash = (msg_id) => {
  return axios.request({
    url: 'api/v1/message/restore',
    method: 'post',
    data: {
      msg_id,
    },
  })
}
