const AgentCLI = require('../../clients/Agent')
const { validateNonEmpty } = require('../../utils')
const { handleError } = require('../../error')
const log = require('../../logging')

async function builder (yargs) {
  yargs.option('verbose', {
    alias: 'v',
    type: 'boolean',
    describe: 'Console will receive verbose error output'
  }).option('project', {
    type: 'input',
    describe: 'Project ID',
    demandOption: true,
    string: true,
    validateNonEmpty
  }).option('instance', {
    type: 'input',
    describe: 'Instance ID',
    demandOption: true,
    string: true,
    validateNonEmpty
  })
}

async function handler (argv) {
  try {
    const agent = new AgentCLI(argv)
    const status = await agent.ready()
    log.plain(JSON.stringify(status))
  } catch (err) {
    handleError(err, 'Query agent ready status failed', argv.verbose)
  }
}

module.exports = {
  builder,
  handler,
  command: 'ready',
  describe: 'Query agent ready status'
}
