import { getRequest, postRequest } from './service';

function getExport(map) {
  let res = {};
  for (var key in map) {
    let url = "";
    let func = getRequest;
    if (typeof map[key] == 'string') {
      url = map[key];
    } else if (map[key].type == 'get') {
      url = map[key].url;
    } else if (map[key].type == 'post') {
      url = map[key].url;
      func = postRequest;
    }
    res[key] = function(params){
      return func(url,params)
    }
  }
  return res;
}

const gameApiMap = {
  // 游戏详情
  getGameInfo: "/gic-wx-app/game",
  // 游戏规则
  getGameRule: "/gic-wx-app/game/rule",
  // 我的抽奖次数
  getGamePlayNumber: "/gic-wx-app/game/play_number",
  // 中奖弹幕
  getGamePlayBarrage: '/gic-wx-app/game/play/barrage',
  // 游戏奖品
  getGameReward: '/gic-wx-app/game/prize',
  // 我的奖品
  getMyReward: '/gic-wx-app/game/member/prize',
  // 规则条件
  getGameRuleCondition: '/gic-wx-app/game/rule_condition',
  // 助力记录
  getReportRecord: '/gic-wx-app/game/help',
  // 查询剩余次数
  getGameNumberPolling: '/gic-wx-app/game/play_number/polling',
  // 玩游戏抽奖
  gamePlay: {
    type: 'post',
    url: '/gic-wx-app/game/play'
  },
  // 校验会员玩游戏权限
  validGame: '/gic-wx-app/game/valid',

  // 获取已玩次数
  getPlayCount: '/gic-wx-app/game/play_count',

  // 获取积分
  getIntegral: '/gic-wx-app/common/integral',

  // 获取分享码
  getGameShareQrCodeUrl: {
    type:"post",
    url: '/gic-wx-app/game/share'
  },

  // 获取助力详情
  getHelpDetail: '/gic-wx-app/game/help_detail',

  // 浏览埋点
  shareEvent: '/api-bury-point/share-event',

}
export const gameRequestApi = getExport(gameApiMap)