import http from '@/utils/request'
/* ---------------------------------------灰名单提示管理--------------------------------------------- */
export function getIdGreyList (params) {
  // eslint-disable-next-line prefer-const
  let { pageNum = 1, pageSize = 10, identity, status = ['inactive', 'active'] } = params

  status = status.map(val => {
    return `status=${val}`
  }).join('&')

  return http.get(`/identityGreyList?${(pageNum === 0 || pageNum) ? `pageNum=${pageNum}` : ''}&${(pageSize === 0 || pageSize) ? `pageSize=${pageSize}` : ''}&${identity ? `identity=${identity}` : ''}&${status}`)
}

export function addId ({ name, content }) {
  return http.post('/identityGreyList', {
    name,
    content
  })
}
export function updateId ({ id, content }) {
  return http.post(`/identityGreyList/${id}`, {
    content
  })
}

export function deleteId (id) {
  return http.delete(`/identityGreyList/${id}`)
}

export function toggleId ({ id, status }) {
  return http.post(`/identityGreyList/${id}/active`, {
    active: status !== 'active'
  })
}

/* ---------------------------------------灰名单管理--------------------------------------------- */
export function getGreyList (params) {
  // eslint-disable-next-line prefer-const
  let { pageNum = 1, pageSize = 10, status = ['inactive', 'active'] } = params

  status = status.map(val => {
    return `status=${val}`
  }).join('&')

  return http.get(`/greyList?${(pageNum === 0 || pageNum) ? `pageNum=${pageNum}` : ''}&${(pageSize === 0 || pageSize) ? `pageSize=${pageSize}` : ''}&${status}`)
}

export function activeGreyList ({ id, status }) {
  return http.post(`/greyList/${id}/active`, {
    active: status !== 'active'
  })
}

export function addGreyList (params) {
  return http.post(`/greyList`, params)
}

export function updateGreyList (params) {
  return http.post(`/greyList/${params.id}`, { greyList_identities: params.greyList_identities })
}

export function deleteGreyList (id) {
  return http.delete(`/greyList/${id}`)
}
