/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ "use strict"; var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__tryCatch=__rt.__tryCatch; var __ = require("underscore");

















var util = require("util");
var utils = require("../../../util/utils");
var insightsUtils = require("./insights.utils");

var $ = utils.getLocaleString;

exports.init = function(cli) {
  var log = cli.output;
  var insightsMetricDefinitionCommand = cli.category("insights").category("metrics").category("definition").description($("Retrieve metric definitions for a resource"));


  insightsMetricDefinitionCommand.command("list <resourceId>").description($("List metric definitions for a resource.")).usage("[options] <resourceId>").option("-i --resourceId <resourceId>", $("The resource Id.")).option("-n --metricNames <metricNames>", $("The list of metric names.")).option("-s --subscription <subscription>", $("The subscription identifier.")).execute(function __1(resourceId, options, _) { var __frame = { name: "__1", line: 36 }; return __func(_, this, arguments, __1, 2, __frame, function __$__1() {






      return insightsMetricDefinitionCommand._prepareAndExecute(resourceId, options, __cb(_, __frame, 1, 40, function __$__1() { _(); }, true)); }); });


  insightsMetricDefinitionCommand._prepareAndExecute = function insightsMetricDefinitionCommand__prepareAndExecute__2(resourceId, options, _) { var client, queryFilter, __this = this; var __frame = { name: "insightsMetricDefinitionCommand__prepareAndExecute__2", line: 40 }; return __func(_, this, arguments, insightsMetricDefinitionCommand__prepareAndExecute__2, 2, __frame, function __$insightsMetricDefinitionCommand__prepareAndExecute__2() {
      log.silly(util.format("Parameters: resourceId=%s, metricNames=%s", resourceId, options.metricNames));
      if (!__.isString(resourceId)) {
        return _(null, cli.missingArgument("resourceId")); } ;


      client = insightsUtils.createInsightsClient(log, options);
      queryFilter = insightsUtils.addMetricNamesFilter(options.metricNames);

      return __this._executeCmd(client, resourceId, queryFilter, insightsUtils.passAllFilter, options, __cb(_, __frame, 9, 16, _, true)); }); };


  insightsMetricDefinitionCommand._executeCmd = function insightsMetricDefinitionCommand__executeCmd__3(client, resourceId, queryFilter, keepTheRecord, options, _) { var progress, result, response; var __frame = { name: "insightsMetricDefinitionCommand__executeCmd__3", line: 52 }; return __func(_, this, arguments, insightsMetricDefinitionCommand__executeCmd__3, 5, __frame, function __$insightsMetricDefinitionCommand__executeCmd__3() {
      progress = cli.interaction.progress(util.format($("Querying \"%s\""), queryFilter));
      result = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$insightsMetricDefinitionCommand__executeCmd__3() {

            return client.metricDefinitionOperations.getMetricDefinitions(resourceId, queryFilter, __cb(_, __frame, 4, 55, function ___(__0, __1) { response = __1;

              log.silly((!response ? util.inspect(response) : "nothing in response"));
              log.silly(((!response && response.metricDefinitionCollection) ? util.inspect(response.metricDefinitionCollection) : "nothing in metricDefinitionCollection"));

              __.each(response.metricDefinitionCollection.value, function(element) { if (keepTheRecord(element)) { result.push(element); } ; }); _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$insightsMetricDefinitionCommand__executeCmd__3() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$insightsMetricDefinitionCommand__executeCmd__3() {


          insightsUtils.formatOutputList(cli, log, options, result); _(); }); }); }); };};
