/*** 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; var profile = require("../../../util/profile");

















var utils = require("../../../util/utils");
var NetworkUsage = require("../network/networkUsage");
var VMClient = require("../vm/vmClient");

var $ = utils.getLocaleString;

exports.init = function(cli) {
  var log = cli.output;

  var usage = cli.category("quotas").description($("Command to view your aggregated Azure quotas"));


  usage.command("show [location]").description($("Show cores, storage account and network quotas for the current subscription")).usage("[options] <location>").option("-l, --location <location>", $("the location")).option("-s, --subscription <subscription>", $("the subscription identifier")).execute(function __1(location, options, _) { var vmClient, networkManagementClient, networkUsage, storageClient, usage; var __frame = { name: "__1", line: 36 }; return __func(_, this, arguments, __1, 2, __frame, function __$__1() {





      return cli.interaction.promptIfNotGiven($("Location: "), location, __cb(_, __frame, 1, 35, function ___(__0, __1) { location = __1;
        location = utils.toLowerCaseAndRemoveSpace(location);


        log.info($("Showing Cores and VM Quotas"));
        vmClient = new VMClient(cli, options.subscription);
        return vmClient.listComputeUsage(location, options, __cb(_, __frame, 7, 17, function __$__1() {
          log.info($("\n"));


          log.info($("Showing Networking Quotas"));
          networkManagementClient = getNetworkManagementClient(options);
          networkUsage = new NetworkUsage(cli, networkManagementClient);
          return networkUsage.list(location, options, __cb(_, __frame, 14, 21, function __$__1() {
            log.info($("\n"));


            log.info($("Showing Storage Accounts Quota (NOTE: Global, not per region)"));
            storageClient = createStorageManagementClient(options.subscription);
            return showStorageUsage(storageClient, options.subscription, __cb(_, __frame, 20, 14, function ___(__0, __2) { usage = __2;
              cli.interaction.formatOutput(usage, function(outputData) {
                log.data($("Subscription:"), outputData.subscriptionId);
                log.data($("Used Storage Accounts:"), outputData.used);
                log.data($("Max Storage Accounts:"), outputData.limit); }); _(); }, true)); }, true)); }, true)); }, true)); }); });



  function getNetworkManagementClient(options) {
    var subscription = profile.current.getSubscription(options.subscription);
    return utils.createNetworkManagementClient(subscription); };


  function createStorageManagementClient(subscriptionOrName) {
    var subscription = profile.current.getSubscription(subscriptionOrName);
    var client = utils.createStorageResourceProviderClient(subscription);

    return client; };


  function showStorageUsage(serviceClient, subscriptionId, _) { var usage, usageList, i; var __frame = { name: "showStorageUsage", line: 76 }; return __func(_, this, arguments, showStorageUsage, 2, __frame, function __$showStorageUsage() {
      usage = { subscription: subscriptionId };

      if (!subscriptionId) {
        usage.subscriptionId = profile.current.getSubscription().id; } ;


      return serviceClient.usageOperations.list(__cb(_, __frame, 7, 50, function ___(__0, __1) { usageList = __1;
        for (i = 0; (i < usageList.value.length); i++) {
          if ((usageList.value[i].name.value === "StorageAccounts")) {
            usage.used = usageList.value[i].currentValue;
            usage.limit = usageList.value[i].limit;
            break; } ; };



        return _(null, usage); }, true)); }); };};
