import request from '@/utils/request'

const api = {
  removeSort: '/toy/relation/getRelatedStatus/'
}
// 查询玩具基础信息列表
export function listInfo(query) {
  return request({
    url: '/toy/info/list',
    method: 'get',
    params: query
  })
}

// 查询玩具基础信息详细
export function getInfo(id) {
  return request({
    url: '/toy/info/' + id,
    method: 'get'
  })
}

// 新增玩具基础信息
export function addInfo(data) {
  return request({
    url: '/toy/info',
    method: 'post',
    data: data
  })
}

// 修改玩具基础信息
export function updateInfo(data) {
  return request({
    url: '/toy/info',
    method: 'put',
    data: data
  })
}

// 修改玩具状态
export function changeToyStatus(toyStatus, idCol) {
  let ids = ''
  if (Object.prototype.toString.call(idCol) === '[object Array]') {
    ids = idCol.join()
  } else {
    ids = idCol
  }
  const data = {
    ids,
    toyStatus
  }
  return request({
    url: '/toy/info/toy-status',
    method: 'put',
    data: data
  })
}

// 查询回收站玩具信息列表
export function toyRecycleInfo(query) {
  return request({
    url: '/toy/recycle/list',
    method: 'get',
    params: query
  })
}

// 恢复玩具基础信息
export function toyRecycle(ids) {
  let idStr = ''
  if (Object.prototype.toString.call(ids) === '[object Array]') {
    idStr = ids.join()
  } else {
    idStr = ids
  }
  return request({
    url: '/toy/recycle/recover',
    method: 'put',
    params: {
      'ids': idStr,
      'recycleStatus': '0'
    }
  })
}

// 彻底删除玩具基础信息
export function toyDelete(ids) {
  let idStr = ''
  if (Object.prototype.toString.call(ids) === '[object Array]') {
    idStr = ids.join()
  } else {
    idStr = ids
  }
  return request({
    url: '/toy/recycle/remove',
    method: 'put',
    params: {
      'ids': idStr,
      'recycleStatus': '2'
    }
  })
}

// 删除玩具基础信息
export function localDelInfo(ids) {
  let idStr = ''
  if (Object.prototype.toString.call(ids) === '[object Array]') {
    idStr = ids.join()
  } else {
    idStr = ids
  }
  return request({
    url: '/toy/recycle/recover',
    method: 'put',
    params: {
      'ids': idStr,
      'recycleStatus': '1'
    }
  })
}

// 删除玩具基础信息
export function delInfo(id) {
  return request({
    url: '/toy/info/' + id,
    method: 'delete'
  })
}

export function editMainCategory(data) {
  return request({
    url: '/toy/info/toy-sort',
    method: 'put',
    data
  })
}

export function objToStrMap(obj) {
  const strMap = new Map()
  for (const k of Object.keys(obj)) {
    strMap.set(k, obj[k])
  }
  return strMap
}

export function classArrToStrMap(obj) {
  const strMap = new Map()
  obj.forEach(item => {
    strMap[item.classId] = item.className
  })
  return strMap
}

export function editToyPlay(data) {
  return request({
    url: 'toy/gameplay/multi-handle',
    method: 'post',
    data
  })
}

export function fetchToyPlay(params) {
  return request({
    url: '/toy/gameplay/list',
    method: 'get',
    params
  })
}

export function fetchToyStatus(params) {
  return request({
    url: 'toy/info/statics/status',
    method: 'get',
    params
  })
}

export function getAssociateList(id) {
  return request({
    url: `toy/info/getToyCorrelationList/${id}`,
    method: 'get'
  })
}
export function cancelCorrelation(data) {
  return request({
    url: `toy/info/cancelCorrelation`,
    method: 'post',
    data
  })
}

export function getToyCorrelationStatus(ids) {
  return request({
    url: `toy/recycle/getToyCorrelationStatus?ids=${ids}`,
    method: 'get'
  })
}

export function removeSortValid(sortId) {
  return request({
    url: api.removeSort + sortId,
    method: 'get'
  })
}
