import api from './request'

// 认证相关API
// 注意：用户名密码登录已禁用，仅支持邮箱验证码登录

// 邮箱验证码登录（唯一登录方式）
export const loginWithEmail = (credentials) => {
  return api.post('/auth/login/email', credentials)
}

// 向后兼容（已禁用）
export const login = (credentials) => {
  return api.post('/auth/login', credentials)
}

export const register = (userData) => {
  return api.post('/auth/register', userData)
}

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

export const getCurrentUser = () => {
  return api.get('/auth/me')
}

// 修改当前登录用户密码
export const changePassword = (data) => {
  return api.post('/auth/change-password', data)
}

// 用户相关API
export const getUsers = (params) => {
  return api.get('/users', { params })
}

export const getUserById = (id) => {
  return api.get(`/users/${id}`)
}

export const createUser = (userData) => {
  return api.post('/users', userData)
}

export const updateUser = (id, userData) => {
  return api.put(`/users/${id}`, userData)
}

export const deleteUser = (id) => {
  return api.delete(`/users/${id}`)
}

// 检查用户名是否存在
export const checkUsernameExists = (username) => {
  return api.get(`/public/users/exists/username`, {
    params: { value: username }
  })
}

// 检查邮箱是否存在
export const checkEmailExists = (email) => {
  return api.get(`/public/users/exists/email`, {
    params: { value: email }
  })
}

// 发送邮箱验证码
export const sendEmailCode = (email) => {
  return api.post('/verification/email/send', { email })
}

// 开发环境：设置验证码（用于开发测试）
export const setDevEmailCode = (email, code) => {
  return api.post('/verification/email/dev-set', { email, code })
}







