import Colls from '@/common/utils/colls.ts'

const clientList = [
  {
    txt: '电脑端',
    val: 1,
  },
  {
    txt: '微信小程序',
    val: 2,
  },
]

function hasClient(client: number, clientCode: number) {
  const find = clientList.find(it => it.val === client)
  if (find == null) return false
  return (client & clientCode) !== 0
}

function getClientCode(clients: number[]) {
  if (Colls.isEmpty(clients)) return 0
  let clientCode = 0
  for (let client of clients) {
    clientCode |= client
  }
  return clientCode
}

function getClients(clientCode: number) {
  return clientList.filter(it => hasClient(it.val, clientCode))
}

export default {
  clients: clientList,
  hasClient,
  getClientCode,
  getClients,
}
