import {
  getToken
} from '@/utils/auth'
import request from '@/utils/request'

export function login(data) {
  console.log('login post data ', data)
  return request({
    url: '/login',
    method: 'post',
    data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/system/user/profile/avatar',
    method: 'post',
    data: data
  })
}

// 注册方法
export function register(data) {
  return request({
    url: '/register',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

export function getInfo(username) {
  return request({
    url: '/users/' + username,
    method: 'get',
    params: {
      token: getToken()
    }
  })
}

export function deleteUser(username) {
  return request({
    url: '/users/' + username,
    method: 'delete'
  })
}

export function updateUser(data) {
  return request({
    url: `/users/${data.username}`,
    method: 'put',
    data
  })
}

export function updateUserPassword(data) {
  return request({
    url: `/users/${data.username}` + '/password',
    method: 'put',
    data
  })
}

export function getAllUsers() {
  return request({
    url: '/users',
    method: 'get'
  })
}

export function createUser(user) {
  return request({
    url: '/users',
    method: 'post',
    data: user
  })
}

export function logout() {
  console.log('start to logout 3')
  return request({
    url: '/user/logout',
    method: 'post'
  })
}
