import axios, { type AxiosResponse } from 'axios'

const BASE_URI = 'http://stage-axds-auth-api.srv.axiomptk'
// TODO: Add a way to set the base URI from the environment

async function requestPasswordReset (email: string): Promise<AxiosResponse<any>> {
  const response = await axios.post(`${BASE_URI}/app/web-app/request_password_reset`, {
    email
  })
  return response
}

async function signIn (email: string, password: string): Promise<AxiosResponse<any>> {
  const response = await axios.post(`${BASE_URI}/app/web-app/login`, {
    email,
    password
  })
  return response
}

async function signUp (firstName: string, lastName: string, email: string, password: string): Promise<AxiosResponse<any>> {
  const response = await axios.post(`${BASE_URI}/app/web-app/user`, {
    first_name: firstName,
    last_name: lastName,
    email,
    password
  })
  return response
}

async function resetPassword (password: string, oneTimePassword: string): Promise<AxiosResponse<any>> {
  const response = await axios.post(`${BASE_URI}/app/web-app/reset_password`, {
    password,
    token: oneTimePassword
  })
  return response
}

export default {
  requestPasswordReset,
  signIn,
  signUp,
  resetPassword
}
