import api from './index.js'

/**
 * 认证相关API接口
 */

// 发送短信验证码
export const sendSmsCode = (phone) => {
  return api.get(`/msm/send/${phone}`)
}

// 短信验证码登录
export const smsLogin = (data) => {
  return api.post('/auth/sms-login', data)
}

// 密码登录
export const passwordLogin = (data) => {
  return api.post('/auth/password-login', data)
}

// 用户注册
export const register = (data) => {
  return api.post('/auth/register', data)
}

// 重置密码
export const resetPassword = (data) => {
  return api.post('/auth/reset-password', data)
}

// 退出登录
export const logout = () => {
  return api.post('/auth/logout')
}

// 获取微信登录二维码
export const getWechatQrCode = (params = {}) => {
  const { isRegister = false, inviteCode = '' } = params
  
  // 如果是注册模式且有邀请码，调用用户接口并拼接邀请码
  if (isRegister && inviteCode) {
    return api.post(`/wechat/qr/login?inviteCode=${encodeURIComponent(inviteCode)}`)
  }
  
  // 默认调用原接口
  return api.post('/wechat/qr/login')
}

// 检查微信登录状态
export const checkWechatLoginStatus = (sceneStr) => {
  return api.post('/wechat/login/check', `sceneStr=${encodeURIComponent(sceneStr)}`, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 更新用户手机号
export const updateUserPhone = (data) => {
  return api.put('/auth/phone', data)
} 