import http from '@/http/api.js'
import {
  bizConst
} from './biz/biz.js'
import {
  clientId,
  tenantId
} from '@/common/setting'

// 获取token
const wxUserLogin = (code) => {
  let tenantId = '000000'
  return http.request({
    url: bizConst.memberPrefix + '/login/miniapp', //?clientCode=' + clientId + '&code=' + code,
    method: 'POST',
    header: {
      'Tenant-Id': tenantId
    },
    params: {
      clientCode: clientId,
      code,
    },
  })
}

//刷新token
const refreshToken = (refreshToken) => {
  return http.request({
    url: bizConst.memberPrefix + '/login/refresh',
    method: 'POST',
    params: {
      refreshToken,
    },
  })
}

//保存昵称和头像
const saveNicknameAndAvatar = (name, avatar) => {
	return http.request({
		url: bizConst.memberPrefix + '/update',
		method: 'POST',
		params: {
			name,
			avatar,
		},
	})
}

const getUserInfo = () => {
  return http.request({
    url: bizConst.memberPrefix + '/info',
    method: 'GET',
    header: {
      'Tenant-Id': tenantId
    },
    params: {},
  })
}
const updateUserInfo = () => {
  return http.request({
    url: bizConst.memberPrefix + '/update',
    method: 'GET',
    header: {
      'Tenant-Id': tenantId
    },
    params: {},
  })
}
export default {
  wxUserLogin,
  refreshToken,
  getUserInfo,
  updateUserInfo,
  saveNicknameAndAvatar
}