
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: '我是admin',
    avatar: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1585553122153&di=c8aca6e85d8139120fbcdee7a9023ce3&imgtype=0&src=http%3A%2F%2Fbpic.588ku.com%2Felement_origin_min_pic%2F00%2F85%2F19%2F5556e88af163dd7.jpg',
    name: 'Admin系统管理员'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: '我是 editor',
    avatar: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1585553170773&di=273b8637b3fcfde75817f066ab1f47c2&imgtype=0&src=http%3A%2F%2Fbpic.588ku.com%2Felement_origin_min_pic%2F01%2F12%2F50%2F2856f5fe2d7c41e.jpg',
    name: 'Editor编辑'
  }
}

export default [
  // 用户登录
  {
    url: '/CAE/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]
      if (!token) {
        return {
          code: 60204,
          message: '用户名或密码不正确！'
        }
      }
      return {
        code: 20000,
        data: token
      }
    }
  },

  // 获取用户信息
  {
    url: '/CAE/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]
      if (!info) {
        return {
          code: 50008,
          message: '登录失败，无法获取用户详细信息！'
        }
      }
      return {
        code: 20000,
        data: info
      }
    }
  },

  // 退出登录
  {
    url: '/CAE/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
