import http from '@/utils/request'

/* -------------------------------------- 身份证 ----------------------------------------- */
export function getIdList (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(`/blacklist/identity?${(pageNum === 0 || pageNum) ? `pageNum=${pageNum}` : ''}&${(pageSize === 0 || pageSize) ? `pageSize=${pageSize}` : ''}&${identity ? `identity=${identity}` : ''}&${status}`)
//   return http.get(`/blacklist/identity`)
}

export function addId ({ identity, description }) {
  return http.post('/blacklist/identity', {
    type: 'ID_CARD',
    identity,
    description
  })
}

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

export function toggleId ({ id, status }) {
  return http.delete(`/blacklist/identity/${id}/active`, {
    data: { active: status !== 'active' }
  })
}

export function updateId ({ id, description }) {
  return http.put(`/blacklist/identity/${id}`, {
    description
  })
}

/* -------------------------------------- 手机号 ----------------------------------------- */
export function getPhoneList (params) {
  // eslint-disable-next-line prefer-const
  let { pageNum = 1, pageSize = 10, phone, status = ['inactive', 'active'] } = params

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

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

export function addPhone ({ phone, description }) {
  return http.post('/blacklist/phone', {
    phone,
    description
  })
}

export function deletePhone (id) {
  return http.delete(`/blacklist/phone/${id}`)
}

export function togglePhone ({ id, status }) {
  return http.delete(`/blacklist/phone/${id}/active`, {
    data: { active: status !== 'active' }
  })
}

export function updatePhone ({ id, description }) {
  return http.put(`/blacklist/phone/${id}`, {
    description
  })
}
