import request from '@/utils/request'
import qs from 'qs'
import { BASE_URL, SERVICE_PLATFORM_POWER_BASE } from '@/config/serviceSettings.js'

const userApi = {
  Login: BASE_URL+'/auth/login',
  Logout:BASE_URL+ '/auth/logout',
  UserMenu: BASE_URL+'/user/nav',
  //UserInfo: SERVICE_PLATFORM_POWER_BASE + '/user/info',
  UserInfo:BASE_URL+ '/user/info',
  Renew: BASE_URL+'/token/refresh',
  UpdateUserInfo: SERVICE_PLATFORM_POWER_BASE + '/userpower/updatePassword'
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login(parameter) {
  return request({
    url: userApi.Login,
    method: 'post',
    data: qs.stringify(parameter),
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  })
}

export function getInfo() {
  return request({
    url: userApi.UserInfo,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * token 续订
 */
export function tokenRenew() {
  return request({
    url: userApi.Renew,
    method: 'get'
  })
}

export function getSmsCaptcha(parameter) {
  return axios({
    url: api.SendSms,
    method: 'post',
    data: parameter
  })
}

export function getCurrentUserNav() {
  return request({
    url: userApi.UserMenu,
    method: 'get'
  })
}

export function logout() {
  return request({
    url: userApi.Logout,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function setUserInfo(parameter) {
  return request({
    url: userApi.UpdateUserInfo,
    method: 'post',
    data: qs.stringify(parameter),
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  })
}
