/* eslint-disable no-prototype-builtins */
const memberInfoConfig = [
  {
    key: 'point',
    text: '会员积分',
    unit: '',
  },
  {
    key: 'balance',
    text: '账户余额',
    unit: '元',
  },
  {
    key: 'level',
    text: '会员等级',
    unit: '',
  },
];
// 寻找对应key 的文字描述
const getConfigTitle = key => {
  const index = memberInfoConfig.findIndex(v => v.key === key);
  // 找到了
  if (index !== -1) {
    return memberInfoConfig[index].text;
  }
  return '';
};

// 寻找对应key 的单位
const getConfigUnit = key => {
  const index = memberInfoConfig.findIndex(v => v.key === key);
  // 找到了
  if (index !== -1) {
    return memberInfoConfig[index].unit;
  }
  return '';
};

// 查询memberInfo 中是否含有对应 key的数据
const hasMemberDataKey = (memberInfo = {}, key) => {
  return memberInfo.hasOwnProperty(key);
};

// 查询 memberInfo 中是否含有某个key
// showInfo: list
const hasSomeMemberDataKey = (memberInfo = {}, showInfo) => {
  return showInfo.some(v => memberInfo.hasOwnProperty(v));
};

export default {
  getConfigTitle,
  getConfigUnit,
  hasMemberDataKey,
  hasSomeMemberDataKey,
};
