const cmd = require('node-cmd');
const Spinner = require('../../lib/Spinner');
const Log = require('../../lib/Log');

function builder(yargs) {
  return yargs
    .option('source', {
      alias: 's',
      type: 'string',
      describe: 'Source of oracle service'
    })
    .example('kaizen oracle --source chainlink')
    .demandOption(['source'], 'Please enter a source name');
}

async function handler(argv) {
  try {
    const { source } = argv;

    if (!source) {
      Log.NormalLog('Missing plugin statement.\nPlease using \'kaizen plugins uninstall [plugin]\'');
      return;
    }
    // TODO create chainlink service
    switch (source) {
      case 'chainlink':
        Log.NormalLog('Installing oracle, please wait a second...');
        Spinner.start();
        // TODO
        // await chainlinkHandler();
        Spinner.stop();
        Log.SuccessLog(`Install oracle ${source} Successfully`);
        break;
      default:
        Log.NormalLog('Oracle source not support yet');
    }
  } catch (error) {
    Spinner.stop();
    Log.ErrorLog('something went wrong!');
    console.error(error);
  }
}

module.exports = function (yargs) {
  const command = 'oracle';
  const commandDescription = 'Create an oracle service';
  yargs.command(command, commandDescription, builder, handler);
}
