/**
 * 门禁授权接口
 */
import request from '@/utils/request'
import qs from 'qs'

// 门禁授权列表查询
export function getDoorPermissionList(params) {
  return request({
    url: 'acsPermission/listDoor',
    method: 'get',
    params
  })
}

// 某门禁员工授权列表
export function getStaffPermissionByDoor(params) {
  return request({
    url: 'acsDeviceCard/listStaffPerm',
    method: 'get',
    params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}
// 某门禁访客授权列表
export function getVisitorPermissionByDoor(params) {
  return request({
    url: 'acsPermission/listVisitorPerm',
    method: 'get',
    params
  })
}
// 新增授权
export function addPermission(form) {
  return request({
    url: 'acsPermission/addBatchStrategyAcs',
    method: 'post',
    params: {
      doorCodes: form.doorCodes,
      strategyId: form.strategyId
    },
    data: form.personList,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

// 取消授权
export function delPermission(doorCodes, cardCodes) {
  return request({
    url: 'acsPermission/deleteBatchDoorAcs',
    method: 'post',
    params: {
      doorCodes: doorCodes
      // strategyId: form.strategyId
    },
    data: cardCodes,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

// 取消授权
export function delAllPermission(doorCodes, personType) {
  return request({
    url: 'acsPermission/deleteBatchAcs',
    method: 'post',
    params: {
      doorCodes: doorCodes
      // personType: personType
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

// 查询员工列表
export function getStaffList(params) {
  return request({
    url: 'acsPermission/listStaff',
    method: 'get',
    params
  })
}

// 查询访客列表
export function getVisitorList(params) {
  return request({
    url: 'acsPermission/listVisitor',
    method: 'get',
    params
  })
}
// 批量导出
export function exportStaffPermission(params) {
  return request({
    url: 'acsPermission/exportStaffPerm',
    method: 'get',
    timeout: 120000,
    params,
    responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}
// 批量导出访客授权记录
export function exportVisitorPermission(params) {
  return request({
    url: 'acsPermission/exportVisitorPerm',
    method: 'get',
    timeout: 120000,
    params,
    responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}
