import { post, put } from '../utils/request'

// 模拟管理员用户数据
const adminUser = {
  id: 1,
  name: '管理员',
  username: 'admin',
  email: 'admin@example.com',
  avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
  role: 'admin'
}

// 模拟普通用户数据
const normalUser = {
  id: 2,
  name: '云帆学员',
  username: 'user',
  email: 'user@example.com',
  avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
  role: 'user'
}


export function registerMethod(registerForm){
  return post('/bs/user/register', registerForm)
}

export function sendVerifyCodeMethod(email){
  return post('/bs/user/getEmailCode',  { email })
}



// 用户登录
export function login(username, password) {
  // 模拟登录逻辑
  return new Promise((resolve) => {
    setTimeout(() => {
      // 根据用户名判断返回管理员还是普通用户
      const userInfo = username === 'admin' ? adminUser : normalUser

      resolve({
        code: 200,
        data: {
          token: 'mock-token-' + Date.now(),
          userInfo
        },
        message: 'success'
      })
    }, 1000)
  })
}

// 更新用户信息
export function updateUserProfile(userId, data) {
  return put(`/users/${userId}`, data)
}
