import get from 'lodash.get'

const apiList = {
//投票信息
 homepage: {
   //获取活动详情信息
  getactivity: {
    url: '/api/voting/:actid',
    method: 'get',
  },
  getactivitylist:{
    url: '/api/voting',
    method: 'get',
  }
},
}

// user.update
// { id: 123 }
export default function getAPI(api, params) {
  if (!api) {
    return apiList;
  }

  const theAPI = get(apiList, api)
  if (!params) {
    return theAPI;
  }

  let url = theAPI.url;
  Object.keys(params).forEach((key) => {
    const val = params[key];

    url = url.replace(new RegExp(':' + key), val)
  })

  return { ...theAPI, url }
}
