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

var utils = require("../../../util/utils");
var profile = require("../../../util/profile");

var AvailabilitySet = require("./availabilitySet");
var NetworkNic = require("./../vm/networkNic");
var VirtualMachine = require("./../vm/virtualMachine");

var $ = utils.getLocaleString;

function AvailsetClient(cli, subscription) {
  this.cli = cli;
  this.subscription = subscription;};


__.extend(AvailsetClient.prototype, {
  createAvailSet: function createAvailSet__1(resourceGroupName, name, location, tags, options, _) { var subscription, serviceClients, params, availSetHelper, availSetResult, __this = this; var __frame = { name: "createAvailSet__1", line: 19 }; return __func(_, this, arguments, createAvailSet__1, 5, __frame, function __$createAvailSet__1() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      params = {
        availsetName: name,
        location: location,
        availsetTags: tags,
        platformUpdateDomainCount: options.platformUpdateDomainCount,
        platformFaultDomainCount: options.platformFaultDomainCount };


      availSetHelper = new AvailabilitySet(__this.cli, serviceClients);
      return availSetHelper.getAvailSet(resourceGroupName, name, __cb(_, __frame, 13, 40, function ___(__0, __1) { availSetResult = __1;
        if (availSetResult) {
          return _(new Error(util.format($("An availability set with name \"%s\" already exists in the resource group \"%s\""), name, resourceGroupName))); } ;


        return availSetHelper.createNewAvailSet(resourceGroupName, params, __cb(_, __frame, 18, 19, function __$createAvailSet__1() { _(); }, true)); }, true)); }); },


  listAvailSet: function listAvailSet__2(resourceGroupName, options, _) { var subscription, serviceClients, availSetHelper, availsetsResult, output, __this = this; var __frame = { name: "listAvailSet__2", line: 40 }; return __func(_, this, arguments, listAvailSet__2, 2, __frame, function __$listAvailSet__2() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      availSetHelper = new AvailabilitySet(__this.cli, serviceClients);
      return availSetHelper.getAvailList(resourceGroupName, __cb(_, __frame, 5, 41, function ___(__0, __1) { availsetsResult = __1;
        output = __this.cli.output;
        __this.cli.interaction.formatOutput(availsetsResult, function(outputData) {
          if ((outputData.length === 0)) {
            output.warn($("No availability sets found")); }
           else {
            output.table(outputData, function(row, item) {
              row.cell($("Name"), item.name);
              row.cell($("Location"), item.location);
              row.cell($("Update domain count"), item.platformUpdateDomainCount);
              row.cell($("Fault domain count"), item.platformFaultDomainCount); }); } ; }); _(); }, true)); }); },





  showAvailSet: function showAvailSet__3(resourceGroupName, name, options, _) { var output, isJson, depth, subscription, serviceClients, dependencies, availsetResult, availabilitySet, __this = this; var __frame = { name: "showAvailSet__3", line: 61 }; return __func(_, this, arguments, showAvailSet__3, 3, __frame, function __$showAvailSet__3() {
      output = __this.cli.output;
      isJson = output.format().json;
      depth = 0;
      if (isJson) {
        if (options.depth) {
          if ((options.depth === "full")) {
            depth = -1; }
           else {
            depth = utils.parseInt(options.depth);
            if (isNaN(depth)) {
              return _(new Error($("--depth is an optional parameter but when specified it must be an integer (number of times to recurse) or text \"full\" (idefinite recursion)"))); } ; } ; } ; }



       else {
        if (options.depth) {
          output.warn($("--depth paramater will be ignored when --json option is not specified")); } ; } ;



      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);
      dependencies = {
        availabilitySet: new AvailabilitySet(__this.cli, serviceClients),
        virtualMachine: new VirtualMachine(__this.cli, serviceClients),
        networkNic: new NetworkNic(__this.cli, serviceClients.networkManagementClient) };


      return dependencies.availabilitySet.getAvailSetByNameExpanded(resourceGroupName, name, depth, { }, dependencies, __cb(_, __frame, 29, 54, function ___(__0, __1) { availsetResult = __1;
        if (availsetResult) {
          availabilitySet = availsetResult;
          __this.cli.interaction.formatOutput(availabilitySet, function() {
            utils.logLineFormat(availabilitySet, output.data); }); }

         else {
          if (isJson) {
            output.json({ }); }
           else {
            output.warn($("No availiability set found")); } ; } ; _(); }, true)); }); },




  deleteAvailSet: function deleteAvailSet__4(resourceGroupName, name, options, _) { var subscription, serviceClients, availSetHelper, availsetResult, __this = this; var __frame = { name: "deleteAvailSet__4", line: 105 }; return __func(_, this, arguments, deleteAvailSet__4, 3, __frame, function __$deleteAvailSet__4() {
      subscription = profile.current.getSubscription(__this.subscription);
      serviceClients = __this._getServiceClients(subscription);

      availSetHelper = new AvailabilitySet(__this.cli, serviceClients);
      return availSetHelper.getAvailSet(resourceGroupName, name, __cb(_, __frame, 5, 40, function ___(__0, __2) { availsetResult = __2;
        if (!availsetResult) {
          return _(new Error(util.format($("An availability set with name \"%s\" not found in the resource group \"%s\""), name, resourceGroupName))); } ; return (function __$deleteAvailSet__4(_) {


          var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return __this.cli.interaction.confirm(util.format($("Delete availability set \"%s\"? [y/n] "), name), __cb(_, __frame, 10, 48, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -104, 21, function ___(__0, __3) { return (function __$deleteAvailSet__4(__then) { if (__3) { return _(null); } else { __then(); } ; })(function __$deleteAvailSet__4() {



            return availSetHelper.deleteAvailSet(resourceGroupName, name, __cb(_, __frame, 14, 19, function __$deleteAvailSet__4() { _(); }, true)); }); }, true)); }, true)); }); },


  _getServiceClients: function(subscription) {
    return {
      computeManagementClient: utils.createComputeManagementClient(subscription),
      storageManagementClient: utils.createStorageResourceProviderClient(subscription),
      networkManagementClient: utils.createNetworkManagementClient(subscription) }; }});




module.exports = AvailsetClient;
