import { get, post } from '../http'

/**
 * 获取专业
 */
const getTags = async (data: { modularId: string }) => {
  return await get<any>('/tag/getTags', { companyFlag: '0', pid: '0', ...data })
}

/**
 * 获取模块
 */
const getList = async (data: any) => {
  return await get<any>('/modular/list', data)
}

const logout = async () => {
  return await get<any>('/logout')
}

/**
 * 微信扫码登录
 * @param weChatCode 微信code
 */
const wxLogin = async (data: {
  clientType: 'MANAGE' | 'PC'
  weChatCode: string
}) => {
  return await post<any>('/wechat/wechatCallback', data)
}

/**
 * 账号密码登录
 * @param account 账号
 * @param password 密码
 */
const login = async (data: { account: string; password: string }) => {
  return await post<any>('/login', { ...data, clientType: 'MANAGE' })
}

/**
 * 修改密码
 * @param code: 验证码
 * @param newPassword 新密码
 * @param phone 手机号
 */
const editPassword = async (data: {
  code: string
  newPassword: string
  phoneNumbers: string
}) => {
  return await post<any>('/sysUser/phoneUpdatePwd', data)
}

/**
 * 获取验证码
 */
const getCaptcha = async () => {
  const time = Date.now()
  sessionStorage.setItem('captchaTime', time.toString())
  return await get<any>(`/getCaptcha/${Date.now()}`)
}

/**
 * 发送验证码
 * @param phoneNumbers 手机号
 */
const sendVerify = async (data: {
  captcha: string
  captchaKey: string
  phone: string
}) => {
  return await post<any>('/sms/sendLoginMessage', data)
}

/**
 * 手机登录
 * @param phone 手机号
 * @param verifyCode 验证码
 */
const phoneLogin = async (data: { phone: string; verifyCode: string }) => {
  return await post<any>('/smsLogin', data)
}

const loginApi = {
  getTags,
  getList,
  logout,
  wxLogin,
  login,
  editPassword,
  getCaptcha,
  sendVerify,
  phoneLogin,
}

export default loginApi
