import request from '@/utils/request'

interface LoginParamsType {
  name?: string // 姓名
  email: string // 邮箱
  password?: string // 密码
  operationType: 'REGISTER' | 'LOGIN' | 'FORGET_PWD'
  verifyCode?: string // 验证码
}

export const precheckAndSendEmail = (data: LoginParamsType): Promise<ApiResponse> => {
  return request({
    url: '/api/auth/precheckAndSendEmail',
    method: 'post',
    data
  })
}

export const fetchRegisterOrLogin = (data: LoginParamsType): Promise<LoginResponse> => {
  return request({
    url: '/api/auth/registerOrLogin',
    method: 'post',
    data
  })
}

export const resetPassword = (data: LoginParamsType): Promise<ApiResponse> => {
  return request({
    url: '/api/auth/forgotPwd',
    method: 'post',
    data
  })
}

export const checkLoginStatus = (): Promise<ApiResponse<LoginResponse>> => {
  return request({
    url: '/api/auth/checkLoginStatus',
    method: 'get'
  })
}

export const LogOut = (): Promise<ApiResponse> => {
  return request({
    url: '/api/auth/logout',
    method: 'get'
  })
}