import utils from '../../utils/lib'

export function login(data) {
  return new Promise((resolve, reject) => {
    utils.SockEventMap.loginResult = res => {
      utils.SockEventMap.loginResult = undefined
      if (res.status) {
        resolve(res.data)
      } else {
        reject(res.msg)
      }
    }
    utils.SendWss('login', {
      'account': data.account,
      'password': utils.EncryptHandler.encrypt(data.password)
    })
  })
}

export function getInfo() {
  return new Promise(resolve => {
    utils.SockEventMap.userInfo = info => {
      utils.SockEventMap.userInfo = undefined
      resolve(info)
    }
    utils.SendWss('getUserInfo', null)
  })
}

export function logout(token) {
  return new Promise(resolve => {
    utils.SockEventMap.logoutResult = () => {
      utils.SockEventMap.logoutResult = undefined
      resolve()
    }
    utils.SendWss('logout', token)
  })
}


