/*** 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;
var constants = require("./constants");
var resourceUtils = require("../resource/resourceUtils");
var tagUtils = require("../tag/tagUtils");

function TrafficManager(cli, trafficManagerManagementClient) {
  this.trafficManagerManagementClient = trafficManagerManagementClient;
  this.output = cli.output;
  this.interaction = cli.interaction;};


__.extend(TrafficManager.prototype, {



  createProfile: function createProfile__1(resourceGroupName, profileName, options, _) { var self, profile, parameters, progress, __this = this; var __frame = { name: "createProfile__1", line: 34 }; return __func(_, this, arguments, createProfile__1, 3, __frame, function __$createProfile__1() { self = __this;


      return self.getProfile(resourceGroupName, profileName, __cb(_, __frame, 3, 23, function ___(__0, __1) { profile = __1;
        if (profile) {
          return _(new Error(util.format($("A Traffic Manager profile with name \"%s\" already exists in resource group \"%s\""), profileName, resourceGroupName))); } ;


        profile = {
          location: constants.trafficManager.defLocation,
          properties: {
            dnsConfig: {
              relativeName: options.relativeDnsName },

            monitorConfig: { },
            endpoints: [] } };



        parameters = self._parseProfile(profile, options, true);
        progress = self.interaction.progress(util.format($("Creating Traffic Manager profile \"%s\""), profileName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createProfile__1() {

              return self.trafficManagerManagementClient.profiles.createOrUpdate(resourceGroupName, profileName, parameters, __cb(_, __frame, 22, 61, function ___(__0, __2) { profile = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$createProfile__1() {

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


            self._showProfile(resourceGroupName, profile.profile); _(); }); }); }, true)); }); },


  setProfile: function setProfile__2(resourceGroupName, profileName, options, _) { var self, profile, parameters, progress, __this = this; var __frame = { name: "setProfile__2", line: 64 }; return __func(_, this, arguments, setProfile__2, 3, __frame, function __$setProfile__2() { self = __this;


      return self.getProfile(resourceGroupName, profileName, __cb(_, __frame, 3, 23, function ___(__0, __1) { profile = __1;
        if (!profile) {
          return _(new Error(util.format($("A Traffic Manager profile with name \"%s\" not found in resource group \"%s\""), profileName, resourceGroupName))); } ;


        parameters = self._parseProfile(profile, options, false);
        progress = self.interaction.progress(util.format($("Updating Traffic Manager profile \"%s\""), profileName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$setProfile__2() {

              return self.trafficManagerManagementClient.profiles.createOrUpdate(resourceGroupName, profileName, parameters, __cb(_, __frame, 11, 61, function ___(__0, __2) { profile = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$setProfile__2() {

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


            self._showProfile(resourceGroupName, profile.profile); _(); }); }); }, true)); }); },


  listProfiles: function listProfiles__3(options, _) { var self, progress, profiles, __this = this; var __frame = { name: "listProfiles__3", line: 83 }; return __func(_, this, arguments, listProfiles__3, 1, __frame, function __$listProfiles__3() { self = __this;


      progress = self.interaction.progress($("Getting Traffic Manager profiles"));
      profiles = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listProfiles__3() { return (function __$listProfiles__3(__then) {

              if (options.resourceGroup) {
                return self.trafficManagerManagementClient.profiles.listAllInResourceGroup(options.resourceGroup, __cb(_, __frame, 7, 64, function ___(__0, __1) { profiles = __1; __then(); }, true)); } else {

                return self.trafficManagerManagementClient.profiles.listAll(__cb(_, __frame, 9, 64, function ___(__0, __2) { profiles = __2; __then(); }, true)); } ; })(function __$listProfiles__3() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listProfiles__3() {


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


          self.interaction.formatOutput(profiles.profiles, function(profiles) {
            if ((profiles.length === 0)) {
              self.output.warn(util.format($("No Traffic Manager profiles found in resource group \"%s\""), resourceGroupName)); }
             else {
              self.output.table(profiles, function(row, profile) {
                row.cell($("Name"), profile.name);
                var resInfo = resourceUtils.getResourceInformation(profile.id);
                row.cell($("Resource group"), resInfo.resourceGroup);
                row.cell($("Status"), profile.properties.profileStatus);
                row.cell($("DNS name"), profile.properties.dnsConfig.relativeName);
                row.cell($("TTL"), profile.properties.dnsConfig.ttl);
                row.cell($("Routing method"), profile.properties.trafficRoutingMethod);
                row.cell($("Monitoring protocol"), profile.properties.monitorConfig.protocol);
                row.cell($("Monitoring path"), profile.properties.monitorConfig.path);
                row.cell($("Monitoring port"), profile.properties.monitorConfig.port);
                row.cell($("Number of endpoints"), (profile.properties.endpoints.length || 0)); }); } ; }); _(); }); }); }); },





  showProfile: function showProfile__4(resourceGroupName, profileName, options, _) { var self, profile, __this = this; var __frame = { name: "showProfile__4", line: 119 }; return __func(_, this, arguments, showProfile__4, 3, __frame, function __$showProfile__4() { self = __this;

      return self.getProfile(resourceGroupName, profileName, __cb(_, __frame, 2, 23, function ___(__0, __1) { profile = __1;

        self._showProfile(resourceGroupName, profile); _(); }, true)); }); },


  getProfile: function getProfile__5(resourceGroupName, profileName, _) { var self, progress, profile, __this = this; var __frame = { name: "getProfile__5", line: 126 }; return __func(_, this, arguments, getProfile__5, 2, __frame, function __$getProfile__5() { self = __this;

      progress = self.interaction.progress(util.format($("Looking up the Traffic Manager profile \"%s\""), profileName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getProfile__5() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getProfile__5() {

                  return self.trafficManagerManagementClient.profiles.get(resourceGroupName, profileName, __cb(_, __frame, 4, 65, function ___(__0, __1) { profile = __1;
                    return _(null, profile.profile); }, true)); }); })(function ___(e, __result) { __catch(function __$getProfile__5() { if (e) {

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

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

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



  deleteProfile: function deleteProfile__6(resourceGroupName, profileName, options, _) { var self, profile, progress, __this = this; var __frame = { name: "deleteProfile__6", line: 142 }; return __func(_, this, arguments, deleteProfile__6, 3, __frame, function __$deleteProfile__6() { self = __this;

      return self.getProfile(resourceGroupName, profileName, __cb(_, __frame, 2, 23, function ___(__0, __2) { profile = __2;

        if (!profile) {
          return _(new Error(util.format("Traffic Manager profile with name \"%s\" not found in the resource group \"%s\"", profileName, resourceGroupName))); } ; return (function __$deleteProfile__6(_) {


          var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Delete Traffic Manager profile \"%s\" ? [y/n] "), profileName), __cb(_, __frame, 8, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -141, 17, function ___(__0, __3) { return (function __$deleteProfile__6(__then) { if (__3) { return _(null); } else { __then(); } ; })(function __$deleteProfile__6() {



            progress = self.interaction.progress(util.format($("Deleting Traffic Manager profile \"%s\""), profileName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteProfile__6() {

                  return self.trafficManagerManagementClient.profiles.deleteMethod(resourceGroupName, profileName, __cb(_, __frame, 14, 51, function __$deleteProfile__6() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteProfile__6() {

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



  checkDnsAvailability: function checkDnsAvailability__7(relativeDnsName, options, _) { var self, parameters, progress, result, __this = this; var __frame = { name: "checkDnsAvailability__7", line: 162 }; return __func(_, this, arguments, checkDnsAvailability__7, 2, __frame, function __$checkDnsAvailability__7() { self = __this;

      parameters = {
        name: relativeDnsName,
        type: "Microsoft.Network/trafficManagerProfiles" };


      progress = self.interaction.progress($("Checking DNS name availability")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$checkDnsAvailability__7() {


            return self.trafficManagerManagementClient.profiles.checkTrafficManagerRelativeDnsNameAvailability(parameters, __cb(_, __frame, 10, 60, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$checkDnsAvailability__7() {

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


          self.interaction.formatOutput(result, function(result) {
            if ((result.nameAvailable === true)) {
              self.output.info(util.format($("The DNS name \"%s\" is available"), result.name)); }
             else {
              self.output.warn(result.message); } ; }); _(); }); }); }); },







  createEndpoint: function createEndpoint__8(resourceGroupName, profileName, endpointName, options, _) { var self, endpoint, parameters, progress, __this = this; var __frame = { name: "createEndpoint__8", line: 189 }; return __func(_, this, arguments, createEndpoint__8, 4, __frame, function __$createEndpoint__8() { self = __this;

      utils.verifyParamExistsInCollection(constants.trafficManager.endpointType, options.type, "--type"); return (function __$createEndpoint__8(__then) {

        if (utils.ignoreCaseEquals(options.type, constants.trafficManager.azureType)) {
          if (options.location) {
            return _(new Error($("The --location should only be specified on endpoints of type 'ExternalEndpoints' and 'NestedEndpoints'"))); } ; __then(); } else {


          return self.interaction.promptIfNotGiven($("Endpoint location: "), options.location, __cb(_, __frame, 9, 42, function ___(__0, __1) { options.location = __1; __then(); }, true)); } ; })(function __$createEndpoint__8() {


        return self.getEndpoint(resourceGroupName, profileName, endpointName, options.type, __cb(_, __frame, 12, 24, function ___(__0, __2) { endpoint = __2;
          if (endpoint) {
            return _(new Error(util.format($("An endpoint with name \"%s\" already exists in Traffic Manager profile \"%s\""), endpointName, profileName))); } ;


          endpoint = {
            name: endpointName,
            properties: { } };


          parameters = self._parseEndpoint(endpoint, options);
          progress = self.interaction.progress(util.format($("Creating endpoint with name \"%s\" in Traffic Manager profile \"%s\""), endpointName, profileName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createEndpoint__8() {

                return self.trafficManagerManagementClient.endpoints.createOrUpdate(resourceGroupName, profileName, options.type, endpointName, parameters, __cb(_, __frame, 25, 63, function ___(__0, __3) { endpoint = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$createEndpoint__8() {

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


              self._showEndpoint(profileName, endpointName, endpoint.endpoint); _(); }); }); }, true)); }); }); },


  setEndpoint: function setEndpoint__9(resourceGroupName, profileName, endpointName, options, _) { var self, endpoint, parameters, progress, __this = this; var __frame = { name: "setEndpoint__9", line: 222 }; return __func(_, this, arguments, setEndpoint__9, 4, __frame, function __$setEndpoint__9() { self = __this;


      return self.getEndpoint(resourceGroupName, profileName, endpointName, options.type, __cb(_, __frame, 3, 24, function ___(__0, __1) { endpoint = __1;
        if (!endpoint) {
          return _(new Error(util.format($("An endpoint with name \"%s\" not found in Traffic Manager profile \"%s\""), endpointName, profileName))); } ;


        parameters = self._parseEndpoint(endpoint, options);
        progress = self.interaction.progress(util.format($("Updating endpoint \"%s\""), endpointName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$setEndpoint__9() {

              return self.trafficManagerManagementClient.endpoints.createOrUpdate(resourceGroupName, profileName, options.type, endpointName, parameters, __cb(_, __frame, 11, 63, function ___(__0, __2) { endpoint = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$setEndpoint__9() {

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


            self._showEndpoint(profileName, endpointName, endpoint.endpoint); _(); }); }); }, true)); }); },


  showEndpoint: function showEndpoint__10(resourceGroupName, profileName, endpointName, options, _) { var self, endpoint, __this = this; var __frame = { name: "showEndpoint__10", line: 241 }; return __func(_, this, arguments, showEndpoint__10, 4, __frame, function __$showEndpoint__10() { self = __this;

      utils.verifyParamExistsInCollection(constants.trafficManager.endpointType, options.type, "--type");

      return self.getEndpoint(resourceGroupName, profileName, endpointName, options.type, __cb(_, __frame, 4, 24, function ___(__0, __1) { endpoint = __1;
        self._showEndpoint(profileName, endpointName, endpoint); _(); }, true)); }); },


  getEndpoint: function getEndpoint__11(resourceGroupName, profileName, endpointName, endpointType, _) { var self, progress, endpoint, __this = this; var __frame = { name: "getEndpoint__11", line: 249 }; return __func(_, this, arguments, getEndpoint__11, 4, __frame, function __$getEndpoint__11() { self = __this;

      progress = self.interaction.progress(util.format($("Looking up the endpoint with name \"%s\" in Traffic Manager profile \"%s\""), endpointName, profileName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getEndpoint__11() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getEndpoint__11() {

                  return self.trafficManagerManagementClient.endpoints.get(resourceGroupName, profileName, endpointType, endpointName, __cb(_, __frame, 4, 67, function ___(__0, __1) { endpoint = __1;
                    return _(null, endpoint.endpoint); }, true)); }); })(function ___(e, __result) { __catch(function __$getEndpoint__11() { if (e) {

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

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

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



  deleteEndpoint: function deleteEndpoint__12(resourceGroupName, profileName, endpointName, options, _) { var self, endpoint, progress, __this = this; var __frame = { name: "deleteEndpoint__12", line: 265 }; return __func(_, this, arguments, deleteEndpoint__12, 4, __frame, function __$deleteEndpoint__12() { self = __this;

      utils.verifyParamExistsInCollection(constants.trafficManager.endpointType, options.type, "--type");

      return self.getEndpoint(resourceGroupName, profileName, endpointName, options.type, __cb(_, __frame, 4, 24, function ___(__0, __2) { endpoint = __2;
        if (!endpoint) {
          return _(new Error(util.format("An endpoint with name \"%s\" not found in Traffic Manager profile \"%s\"", endpointName, profileName))); } ; return (function __$deleteEndpoint__12(_) {


          var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Delete endpoint \"%s\" ? [y/n] "), endpointName), __cb(_, __frame, 9, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -264, 17, function ___(__0, __3) { return (function __$deleteEndpoint__12(__then) { if (__3) { return _(null); } else { __then(); } ; })(function __$deleteEndpoint__12() {



            progress = self.interaction.progress(util.format($("Deleting endpoint \"%s\""), endpointName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteEndpoint__12() {

                  return self.trafficManagerManagementClient.endpoints.deleteMethod(resourceGroupName, profileName, options.type, endpointName, __cb(_, __frame, 15, 52, function __$deleteEndpoint__12() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteEndpoint__12() {

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






  _parseProfile: function(profile, options, useDefaults) {
    var self = this;

    if (options.profileStatus) {
      profile.properties.profileStatus = utils.verifyParamExistsInCollection(constants.trafficManager.status, options.profileStatus, "--profile-status"); } ;


    if (options.trafficRoutingMethod) {
      profile.properties.trafficRoutingMethod = utils.verifyParamExistsInCollection(constants.trafficManager.routingMethod, options.trafficRoutingMethod, "--traffic-routing-method"); }
     else if (useDefaults) {
      var defRoutingMethod = constants.trafficManager.routingMethod[0];
      self.output.warn(util.format($("Using default routing method: %s"), defRoutingMethod));
      profile.properties.trafficRoutingMethod = defRoutingMethod; }  ;


    if (options.ttl) {
      var ttl = parseInt(options.ttl);
      if ((!ttl || (ttl < 0))) {
        throw new Error("time to live parameter must be a positive integer value"); } ;

      profile.properties.dnsConfig.ttl = options.ttl; }
     else if (useDefaults) {
      var defTtl = constants.trafficManager.defTtl;
      self.output.warn(util.format($("Using default ttl: %s"), defTtl));
      profile.properties.dnsConfig.ttl = defTtl; }  ;


    if (options.monitorProtocol) {
      profile.properties.monitorConfig.protocol = utils.verifyParamExistsInCollection(constants.trafficManager.protocols, options.monitorProtocol, "--monitor-protocol"); }
     else if (useDefaults) {
      var defProtocol = constants.trafficManager.protocols[0];
      self.output.warn(util.format($("Using default monitor protocol: %s"), defProtocol));
      profile.properties.monitorConfig.protocol = defProtocol; }  ;


    if (options.monitorPort) {
      var monitorPort = parseInt(options.monitorPort);
      if ((!monitorPort || (monitorPort < 0))) {
        throw new Error("monitor port parameter must be a positive integer value"); } ;

      profile.properties.monitorConfig.port = options.monitorPort; }
     else if (useDefaults) {
      var defPort;
      if ((profile.properties.monitorConfig.protocol === "http")) {
        defPort = constants.trafficManager.unsecurePort; } ;

      if ((profile.properties.monitorConfig.protocol === "https")) {
        defPort = constants.trafficManager.securePort; } ;

      self.output.warn(util.format($("Using default monitor port: %s"), defPort));
      profile.properties.monitorConfig.port = defPort; }  ;


    if (options.monitorPath) {
      if (!utils.stringStartsWith(options.monitorPath, "/", true)) {
        self.output.warn(util.format($("The monitoring path \"%s\" must start with a forward slash, slash added"), options.monitorPath));
        options.monitorPath = ("/" + options.monitorPath); } ;

      profile.properties.monitorConfig.path = options.monitorPath; }
     else if (useDefaults) {
      var defPath = constants.trafficManager.defMonitorPath;
      self.output.warn(util.format($("Using default monitor path: %s"), defPath));
      profile.properties.monitorConfig.path = defPath; }  ;


    if (options.tags) {
      if (utils.argHasValue(options.tags)) {
        tagUtils.appendTags(profile, options); }
       else {
        profile.tags = { }; } ; } ;



    var parameters = {
      profile: profile };


    return parameters; },


  _parseEndpoint: function(endpoint, options) {
    var self = this;
    var typePrefix = constants.trafficManager.typePrefix;

    if (options.type) {
      utils.verifyParamExistsInCollection(constants.trafficManager.endpointType, options.type, "--type");
      endpoint.type = (typePrefix + options.type); } ;


    if ((options.target && options.targetResourceId)) {
      throw new Error($("--target and --target-resource-id parameters are mutually exclusive")); } ;


    if (options.target) {
      if (!utils.ignoreCaseEquals(endpoint.type, (typePrefix + constants.trafficManager.externalType))) {
        throw new Error(util.format($("--target parameter is valid only for endpoint of type \"%s\""), constants.trafficManager.externalType)); } ;

      if (utils.stringEndsWith(options.target, ".", true)) {
        self.output.warn(util.format($("The domain name \"%s\" ends with a dot, dot removed"), options.target));
        options.target = utils.trimTrailingChar(options.target, "."); } ;

      endpoint.properties.target = options.target; } ;


    if (options.targetResourceId) {
      if ((!utils.ignoreCaseEquals(endpoint.type, (typePrefix + constants.trafficManager.azureType)) && !utils.ignoreCaseEquals(endpoint.type, (typePrefix + constants.trafficManager.nestedType)))) {
        throw new Error(util.format($("--target-resource-id parameter is valid only for endpoint of type \"%s\" or \"%s\""), constants.trafficManager.azureType, constants.trafficManager.nestedType)); } ;

      endpoint.properties.targetResourceId = options.targetResourceId; } ;


    if (options.location) {
      endpoint.properties.endpointLocation = options.location; } ;


    if (options.status) {
      endpoint.properties.endpointStatus = utils.verifyParamExistsInCollection(constants.trafficManager.status, options.status, "--status"); } ;


    if (options.weight) {
      var weight = utils.parseInt(options.weight);
      if (((isNaN(weight) || (weight < constants.trafficManager.weightMin)) || (weight > constants.trafficManager.weightMax))) {
        throw new Error(util.format($("--weight must be an integer between %s and %s"), constants.trafficManager.weightMin, constants.trafficManager.weightMax)); } ;

      endpoint.properties.weight = weight; } ;


    if (options.priority) {
      var priority = utils.parseInt(options.priority);
      if (((isNaN(priority) || (priority < constants.trafficManager.priorityMin)) || (priority > constants.trafficManager.priorityMax))) {
        throw new Error(util.format($("--priority must be an integer between %s and %s"), constants.trafficManager.priorityMin, constants.trafficManager.priorityMax)); } ;

      endpoint.properties.priority = priority; } ;


    var parameters = {
      endpoint: endpoint };


    return parameters; },


  _showProfile: function(resourceGroupName, profile) {
    var self = this;
    self.interaction.formatOutput(profile, function(profile) {
      if ((profile === null)) {
        self.output.warn(util.format($("A Traffic Manager profile with name \"%s\" not found in the resource group \"%s\""), profile.name, resourceGroupName)); }
       else {
        self.output.nameValue($("Id"), profile.id);
        self.output.nameValue($("Name"), profile.name);
        self.output.nameValue($("Type"), profile.type);
        self.output.nameValue($("Status"), profile.properties.profileStatus);
        self.output.nameValue($("Routing method"), profile.properties.trafficRoutingMethod);
        self.output.nameValue($("Tags"), tagUtils.getTagsInfo(profile.tags));
        self.output.header($("DNS config"));
        self.output.nameValue($("Relative name"), profile.properties.dnsConfig.relativeName, 2);
        self.output.nameValue($("FQDN"), profile.properties.dnsConfig.fqdn, 2);
        self.output.nameValue($("TTL"), profile.properties.dnsConfig.ttl, 2);
        self.output.header($("Monitor config"));
        self.output.nameValue($("Protocol"), profile.properties.monitorConfig.protocol, 2);
        self.output.nameValue($("Port"), profile.properties.monitorConfig.port, 2);
        self.output.nameValue($("Path"), profile.properties.monitorConfig.path, 2);

        var endpoints = profile.properties.endpoints;
        if ((endpoints.length !== 0)) {
          self.output.header($("Endpoints"));
          self.output.table(endpoints, function(row, ep) {
            row.cell($("Name"), ep.name);
            row.cell($("Target"), ep.properties.target);
            row.cell($("Status"), ep.properties.endpointStatus);
            row.cell($("Location"), (ep.properties.endpointLocation || ""));
            row.cell($("Weight"), ep.properties.weight);
            row.cell($("Priority"), ep.properties.priority);
            row.cell($("Type"), ep.type.replace(constants.trafficManager.typePrefix, "")); }); } ; } ; }); },






  _showEndpoint: function(profileName, endpointName, endpoint) {
    var self = this;
    self.interaction.formatOutput(endpoint, function(endpoint) {
      if ((endpoint === null)) {
        self.output.warn(util.format($("An endpoint with name \"%s\" not found in Traffic Manager profile \"%s\""), endpointName, profileName)); }
       else {
        self.output.nameValue($("Id"), endpoint.id);
        self.output.nameValue($("Name"), endpoint.name);
        self.output.nameValue($("Type"), endpoint.type);
        self.output.nameValue($("Location"), endpoint.properties.endpointLocation);
        self.output.nameValue($("Status"), endpoint.properties.endpointStatus);
        self.output.nameValue($("Target"), endpoint.properties.target);
        self.output.nameValue($("Target resource id"), endpoint.properties.targetResourceId);
        self.output.nameValue($("Weight"), endpoint.properties.weight);
        self.output.nameValue($("Priority"), endpoint.properties.priority); } ; }); }});





module.exports = TrafficManager;
