import { axios } from '@/utils/request'
import { stringify } from 'qs'
import BaseTool from '@/utils/tool'

/**
 * user page func
 * parameter: {
 *     keyword: '',
 * }
 * @param parameter
 * @returns {*}
 */
export function getLogPage (parameter) {
  return axios({
    url: `/upms/logs/page?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * role list func
 * @param parameter
 * @returns {*}
 */
export function queryLog (parameter) {
  console.log('parameter', stringify(parameter))
  return axios({
    url: `/upms/logs?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function addLog (parameter) {
  return axios({
    url: `/upms/logs`,
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

export function updateLog (parameter) {
  if (BaseTool.String.isBlank(parameter.id)) {
    parameter.id = null
    return addLog(parameter)
  }
  return axios({
    url: `/upms/logs/${parameter.id}`,
    method: 'PUT',
    data: parameter
  })
}

export function fetchLog (parameter) {
  return axios({
    url: `/upms/logs/${parameter.id}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function deleteLogs (parameter) {
  return axios({
    url: `/upms/logs`,
    method: 'DELETE',
    data: parameter
  })
}

export function deleteAllLogs () {
  return axios({
    url: `/upms/logs/all`,
    method: 'DELETE'
  })
}
