import request from '@/utils/request'
import { encryptedData } from '@/utils/encrypt'
import { loginRSA, URL } from '@/config'

export async function login(data) {
  if (loginRSA) {
    const password = await encryptedData(data.password)

    data = Object.assign({}, data)
    data.password = password
  }
  return request({
    url: URL.account.user.base.login,
    method: 'post',
    data,
  })
}

export async function socialLogin(data) {
  if (loginRSA) {
    data = await encryptedData(data)
  }
  return request({
    url: '/socialLogin',
    method: 'post',
    data,
  })
}

export function getUserInfo() {
  return request({
    url: URL.account.user.base.userInfo,
    method: 'get',
  })
}

export function logout() {
  return request({
    // url: '/logout',
    url: URL.account.user.base.logout,
    method: 'get',
  })
}

export function register(data) {
  return request({
    url: URL.account.user.base.register,
    method: 'post',
    data,
  })
}
