/*** 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,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var __ = require("underscore");















var util = require("util");
var utils = require("../../../util/utils");
var $ = utils.getLocaleString;

function ReservedIp(cli, networkManagementClient) {
  this.networkManagementClient = networkManagementClient;
  this.output = cli.output;
  this.interaction = cli.interaction;};


__.extend(ReservedIp.prototype, {
  create: function create__1(name, location, options, _) { var self, params, progress, __this = this; var __frame = { name: "create__1", line: 28 }; return __func(_, this, arguments, create__1, 3, __frame, function __$create__1() { self = __this;


      params = {
        name: name,
        location: location };


      if (options.label) {
        params.label = options.label; } ;


      progress = self.interaction.progress($("Creating reserved IP address")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$create__1() {

            return self.networkManagementClient.reservedIPs.create(params, __cb(_, __frame, 14, 47, function __$create__1() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$create__1() {

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



  list: function list__2(options, _) { var self, progress, reservedIPs, __this = this; var __frame = { name: "list__2", line: 48 }; return __func(_, this, arguments, list__2, 1, __frame, function __$list__2() { self = __this;


      progress = self.interaction.progress($("Getting reserved IP addresses")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$list__2() {


            return self.networkManagementClient.reservedIPs.list(__cb(_, __frame, 6, 61, function ___(__0, __1) { reservedIPs = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$list__2() {

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


          self.interaction.formatOutput(reservedIPs.reservedIPs, function(data) {
            if ((data.length === 0)) {
              self.output.warn($("No reserved IP addresses found")); }
             else {
              self.output.table(data, function(row, ip) {
                row.cell($("Name"), ip.name);
                row.cell($("Location"), ip.location);
                row.cell($("Address"), ip.address);
                row.cell($("Label"), (ip.label || ""));
                row.cell($("State"), ip.state); }); } ; }); _(); }); }); }); },





  show: function show__3(name, options, _) { var self, reservedIP, __this = this; var __frame = { name: "show__3", line: 74 }; return __func(_, this, arguments, show__3, 2, __frame, function __$show__3() { self = __this;

      return self.get(name, __cb(_, __frame, 2, 26, function ___(__0, __1) { reservedIP = __1;

        if (reservedIP) {
          self.interaction.formatOutput(reservedIP, function(ip) {
            self.output.nameValue($("Name"), ip.name);
            self.output.nameValue($("Location"), ip.location);
            self.output.nameValue($("Address"), ip.address);
            self.output.nameValue($("Label"), (ip.label || ""));
            self.output.nameValue($("State"), ip.state); }); }

         else {
          if (self.output.format().json) {
            self.output.json({ }); }
           else {
            self.output.warn(util.format($("A reserved ip address with name \"%s\" not found"), name)); } ; } ; _(); }, true)); }); },




  delete: function delete__4(name, options, _) { var self, progress, __this = this; var __frame = { name: "delete__4", line: 95 }; return __func(_, this, arguments, delete__4, 2, __frame, function __$delete__4() { self = __this;


      progress = self.interaction.progress($("Looking up reserved IP address")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$delete__4() { return (function __$delete__4(__then) {

              if (!options.quiet) {

                return self.networkManagementClient.reservedIPs.get(name, __cb(_, __frame, 7, 49, function __$delete__4() {
                  return self.interaction.confirm(util.format($("Delete reserved IP address %s? [y/n] "), name), __cb(_, __frame, 8, 30, function ___(__0, __2) { var __1 = !__2; return (function __$delete__4(__then) { if (__1) { return _(null); } else { __then(); } ; })(__then); }, true)); }, true)); } else { __then(); } ; })(function __$delete__4() {



              progress = self.interaction.progress($("Deleting reserved IP address"));
              return self.networkManagementClient.reservedIPs.deleteMethod(name, __cb(_, __frame, 13, 47, function __$delete__4() { _(null, null, true); }, true)); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$delete__4() {

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



  get: function get__5(name, _) { var self, progress, reservedIP, __this = this; var __frame = { name: "get__5", line: 114 }; return __func(_, this, arguments, get__5, 1, __frame, function __$get__5() { self = __this;

      progress = self.interaction.progress(util.format($("Looking up the reserved ip \"%s\""), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$get__5() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$get__5() {

                  return self.networkManagementClient.reservedIPs.get(name, __cb(_, __frame, 4, 64, function ___(__0, __1) { reservedIP = __1;
                    return _(null, reservedIP); }, true)); }); })(function ___(e, __result) { __catch(function __$get__5() { if (e) {

                    if ((e.statusCode === 404)) {
                      return _(null, null); } ;

                    return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$get__5() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$get__5() {

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





module.exports = ReservedIp;
