import {client, processResponse} from '../client'
import {apiUrls as api} from "src/api/api-urls";
import qs from "qs";

const authApi = {
  login, checkLoginStatus, logout, modifyPassword
}
async function login(username, password) {
  const request = {username: username, password: password}

  // const response = await http.post(api.auth.login, qs.stringify(request))
  const response = await client.post(api.auth.login, request)
  return processResponse(response)
}

async function checkLoginStatus() {
  const response = await client.get(api.auth.loginStatus)
  return processResponse(response)

}

async function logout() {
  const response = await client.get(api.auth.logout)
  return processResponse(response)

}

async function modifyPassword(oldPassword, newPassword) {
  const data = {
    old: oldPassword,
    new: newPassword
  }

  const response = await client.post(api.auth.modifyPassword, qs.stringify(data))

  return processResponse(response)
}

export default authApi
