import request from "@/utils/request.js";

const baseURL = import.meta.env.VITE_APP_BASE_API

/**
 * @description 注册
 * @params email，password
 * @returns data
 */
export function register(data) {
  return request({
    // url: `/api/user/doRegisterByEmail`,
    url: `/api/user/doRegisterByPhone`,
    method: 'post',
    data
  })
}

/**
 * @description 登录
 * @params email，password，code
 * @returns data
 */
export function login(data) {
  return request({
    // url: `/api/user/loginByEmail`,
    url: `/api/user/login`,
    method: 'post',
    data
  })
}

/**
/**
 * @description:重新发送邮件
 * @param {string} data
 * @return: data
 */
export function sendRegisterEmail(email) {
  return request({
    url: `/api/user/sendRegisterEmail`,
    method: 'post',
    data: {
      email
    }
  })
}

/**
/**
 * @description:忘记密码发送邮件
 * @param {string} data
 * @return: data
 */
// export function sendUpdPwdEmailApi(email) {
//   return request({
//     url: `/api/user/sendUpdPwdEmail`,
//     method: 'post',
//     data: {
//       email
//     }
//   })
// }
/**`/api/user/sendLoginPhoneCode?phone=${phone}`
 * @description 忘记密码第一步,根据图片验证码和手机号获取短信
 * @param {object} loginParams (phone,code)
 * @returns data
 */
export function sendUpdPwdEmailApi(data) {
  return request({
    url: `/api/user/sendPhoneCode?phone=${data.phone}&code=${data.code}`,
    method: 'get',
  })
}

/**`/api/user/sendLoginPhoneCode?phone=${phone}`
 * @description 忘记密码第二步,短信验证码和新密码
 * @param {object} loginParams (phone,code,pwd)
 * @returns data
 */
export function doUpdPassApi(loginParams) {
  return request({
    url: `/api/user/updPass`,
    method: 'post',
    data: loginParams
  })
}

/**
 * @description 获取手机验证码
 * @param {number} phone
 * @returns data
 */
export function getSMSToLoginApi(phone) {
  return request({
    url: `/api/user/sendLoginPhoneCode?phone=${phone}`,
    method: 'get'
  })
}

/**
 * @description 短信验证码登录
 * @param {object} loginParams (phone,code)
 * @returns data
 */
export function loginByMSMApi(loginParams) {
  return request({
    url: `/api/user/doLoginByPhone`,
    method: 'post',
    data: loginParams
  })
}


/**
 * @description 查询用户邀请码状态
 * @returns data
 */
export function doFindInviteCode() {
  return request({
    url: `/api/inviteCode/find`,
    method: 'get',
  })
}

/**
 * @description 更新邀请码
 * @param {object} inviteCodeData
 * @returns data
 */
export function doUpdateInviteCode(inviteCodeData) {
  return request({
    url: `/api/inviteCode/update`,
    method: 'post',
    data: inviteCodeData
  })
}







/**
/**
 * @description:邮件重置密码,
 * @param pwd, ticket
 * @return: data
 */
export function resetPwdEmailApi(data) {
  return request({
    url: `/api/user/doUpdPass`,
    method: 'post',
    data
  })
}

/**
/**
 * @description:邮件重置密码,
 * @param oldpwd, newpwd
 * @return: data
 */
export function resetPwdFormApi(data) {
  return request({
    url: `/api/user/oldUpdPass`,
    method: 'post',
    data
  })
}


/**
* @description:获取图形验证码
* @return: 验证码地址
*/
export const getCodeImgUrl = baseURL + '/api/user/captcha.jpg'

