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

const Query1 = query => {
  return new Promise(resolve => {
    utils.SockEventMap.adminDashboardQuerySelfRes = data => {
      utils.SockEventMap.adminDashboardQuerySelfRes = undefined
      resolve(data)
    }
    utils.SendWss('adminDashboardQuerySelf', query)
  })
}

const Query2 = query => {
  return new Promise(resolve => {
    utils.SockEventMap.adminDashboardRankDevicesRes = data => {
      utils.SockEventMap.adminDashboardRankDevicesRes = undefined
      resolve(data)
    }
    utils.SendWss('adminDashboardRankDevices', query)
  })
}

const Query2Detail = query => {
  return new Promise(resolve => {
    utils.SockEventMap.adminDashboardQueryDeviceRes = data => {
      utils.SockEventMap.adminDashboardQueryDeviceRes = undefined
      resolve(data)
    }
    utils.SendWss('adminDashboardQueryDevice', query)
  })
}

const Query3 = query => {
  return new Promise(resolve => {
    utils.SockEventMap.adminDashboardRankWinesRes = data => {
      utils.SockEventMap.adminDashboardRankWinesRes = undefined
      resolve(data)
    }
    utils.SendWss('adminDashboardRankWines', query)
  })
}

const Query3Detail = query => {
  return new Promise(resolve => {
    utils.SockEventMap.adminDashboardQueryWineRes = data => {
      utils.SockEventMap.adminDashboardQueryWineRes = undefined
      resolve(data)
    }
    utils.SendWss('adminDashboardQueryWine', query)
  })
}

const Query4 = query => {
  return new Promise(resolve => {
    utils.SockEventMap.adminDashboardRankWorkersRes = data => {
      utils.SockEventMap.adminDashboardRankWorkersRes = undefined
      resolve(data)
    }
    utils.SendWss('adminDashboardRankWorkers', query)
  })
}

const Query4Detail = query => {
  return new Promise(resolve => {
    utils.SockEventMap.adminDashboardQueryWorkerRes = data => {
      utils.SockEventMap.adminDashboardQueryWorkerRes = undefined
      resolve(data)
    }
    utils.SendWss('adminDashboardQueryWorker', query)
  })
}

export default {
  Query1, Query2, Query2Detail, Query3, Query3Detail, Query4, Query4Detail
}
