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

const Query = query => {
  return new Promise(resolve => {
    utils.SockEventMap.queryResult = data => {
      utils.SockEventMap.queryResult = undefined
      resolve(data)
    }
    utils.SendWss('query', query)
  })
}
const QueryDetail = query => {
  return new Promise(resolve => {
    utils.SockEventMap.detailResult = data => {
      utils.SockEventMap.detailResult = undefined
      resolve(data)
    }
    utils.SendWss('detail', query)
  })
}

const QueryReady = query => {
  return new Promise(resolve => {
    utils.SockEventMap.readyResult = data => {
      utils.SockEventMap.readyResult = undefined
      resolve(data)
    }
    utils.SendWss('ready', query)
  })
}

const QueryFinish = query => {
  return new Promise(resolve => {
    utils.SockEventMap.finishResult = data => {
      utils.SockEventMap.finishResult = undefined
      resolve(data)
    }
    utils.SendWss('finish', query)
  })
}


export default {
  Query, QueryDetail, QueryReady, QueryFinish
}
