/*** 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 NetworkNic = require("./networkNic");
var util = require("util");
var utils = require("../../../util/utils");
var $ = utils.getLocaleString;

function VMNetworkProfile(cli, resourceGroupName, params, serviceClients) {
  this.cli = cli;
  this.resourceGroupName = resourceGroupName;
  this.params = params;
  this.serviceClients = serviceClients;};


__.extend(VMNetworkProfile.prototype, {
  generateNetworkProfile: function generateNetworkProfile__1(_) { var networkProfile, nicParamsSpecified, validNICs, networkNic, nicInfo, __this = this; var __frame = { name: "generateNetworkProfile__1", line: 31 }; return __func(_, this, arguments, generateNetworkProfile__1, 0, __frame, function __$generateNetworkProfile__1() {
      networkProfile = {
        profile: {
          networkInterfaces: [] } }; return (function __$generateNetworkProfile__1(__then) {



        if ((__this.params.nicIds || __this.params.nicNames)) {
          nicParamsSpecified = utils.atLeastOneParameIsSet([__this.params.nicName,__this.params.nicId,__this.params.subnetId,__this.params.vnetName,__this.params.vnetSubnetName,__this.params.vnetSubnetAddressprefix,__this.params.vnetAddressPrefix,]);






          if (nicParamsSpecified) {
            __this.cli.output.warn(("Found --nic-ids or --nic-names parameters. --nic-name, --nic-id, --subnet-id and any --vnet-* parameters will be ignored")); } ;

          return __this.validateNICs(__cb(_, __frame, 18, 27, function ___(__0, __1) { validNICs = __1;
            networkProfile.profile.networkInterfaces = validNICs; __then(); }, true)); } else {

          networkNic = new NetworkNic(__this.cli, __this.serviceClients.networkResourceProviderClient, __this.resourceGroupName, __this.params);
          return networkNic.createOrUpdateNICIfRequired(__cb(_, __frame, 22, 31, function ___(__0, __2) { nicInfo = __2;
            networkProfile.profile.networkInterfaces.push({ id: nicInfo.profile.id }); __then(); }, true)); } ; })(function __$generateNetworkProfile__1() {


        return _(null, networkProfile); }); }); },


  validateNICs: function validateNICs__2(_) { var networkInterfaces, __this = this; var __frame = { name: "validateNICs__2", line: 60 }; return __func(_, this, arguments, validateNICs__2, 0, __frame, function __$validateNICs__2() {
      networkInterfaces = []; return (function __$validateNICs__2(__then) {
        if (__this.params.nicIds) {
          return __this._validateNICsById(__cb(_, __frame, 3, 31, function ___(__0, __1) { networkInterfaces = __1; __then(); }, true)); } else { __then(); } ; })(function __$validateNICs__2() { return (function __$validateNICs__2(__then) {


          if (__this.params.nicNames) { return (function __$validateNICs__2(__then) {
              if (__this.params.nicIds) {
                __this.cli.output.warn($("--nic-names parameter will be ignored, because --nic-ids is specified.")); __then(); } else {

                return __this._validateNICsByName(__cb(_, __frame, 10, 33, function ___(__0, __2) { networkInterfaces = __2; __then(); }, true)); } ; })(__then); } else { __then(); } ; })(function __$validateNICs__2() {



          if ((networkInterfaces.length === 0)) {
            return _(new Error($("No valid network interfaces were specified."))); } ;


          return _(null, networkInterfaces); }); }); }); },


  _validateNICsById: function _validateNICsById__3(_) { var validNetworkInterfaces, networkNic, networkInterfaces, i, nicId, nicInfo, __this = this; var __frame = { name: "_validateNICsById__3", line: 81 }; return __func(_, this, arguments, _validateNICsById__3, 0, __frame, function __$_validateNICsById__3() {
      validNetworkInterfaces = [];
      networkNic = new NetworkNic(__this.cli, __this.serviceClients.networkResourceProviderClient, __this.resourceGroupName, __this.params);
      networkInterfaces = utils.stringTrimEnd(__this.params.nicIds, ",").split(",");
      i = 0; var __3 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$_validateNICsById__3() { __more = false; if (__3) { i++; } else { __3 = true; } ; var __2 = (i < networkInterfaces.length); if (__2) {
            nicId = networkInterfaces[i];
            return networkNic.getNICInfoById(nicId, __cb(_, __frame, 6, 31, function ___(__0, __1) { nicInfo = __1;
              if (!nicInfo.profile) {
                __this.cli.output.warn(util.format($("NIC with id \"%s\" was not found."), nicId)); while (__more) { __loop(); }; __more = true; return; } ;




              validNetworkInterfaces.push({ id: nicInfo.profile.id, primary: (validNetworkInterfaces.length === 0) }); while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$_validateNICsById__3() {


        return _(null, validNetworkInterfaces); }); }); },


  _validateNICsByName: function _validateNICsByName__4(_) { var validNetworkInterfaces, networkNic, networkInterfaces, i, nicName, nicInfo, __this = this; var __frame = { name: "_validateNICsByName__4", line: 100 }; return __func(_, this, arguments, _validateNICsByName__4, 0, __frame, function __$_validateNICsByName__4() {
      validNetworkInterfaces = [];
      networkNic = new NetworkNic(__this.cli, __this.serviceClients.networkResourceProviderClient, __this.resourceGroupName, __this.params);
      networkInterfaces = utils.stringTrimEnd(__this.params.nicNames, ",").split(",");
      i = 0; var __3 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$_validateNICsByName__4() { __more = false; if (__3) { i++; } else { __3 = true; } ; var __2 = (i < networkInterfaces.length); if (__2) {
            nicName = networkInterfaces[i];
            return networkNic.getNICInfoByName(__this.resourceGroupName, nicName, __cb(_, __frame, 6, 31, function ___(__0, __1) { nicInfo = __1;
              if (!nicInfo.profile) {
                __this.cli.output.warn(util.format($("NIC with name \"%s\" was not found."), nicName)); while (__more) { __loop(); }; __more = true; return; } ;




              validNetworkInterfaces.push({ id: nicInfo.profile.id, primary: (validNetworkInterfaces.length === 0) }); while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$_validateNICsByName__4() {


        return _(null, validNetworkInterfaces); }); }); }});



module.exports = VMNetworkProfile;
