/*** 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 constants = require("./constants");
var fs = require("fs");
var resourceUtils = require("../resource/resourceUtils");
var recordSetUtils = require("./recordSetUtils");
var tagUtils = require("../tag/tagUtils");
var ZoneFile = require("./zoneFile");
var util = require("util");
var utils = require("../../../util/utils");
var $ = utils.getLocaleString;

function DnsZone(cli, dnsManagementClient) {
  this.dnsManagementClient = dnsManagementClient;
  this.zoneFile = new ZoneFile(cli.output);
  this.output = cli.output;
  this.interaction = cli.interaction;};


__.extend(DnsZone.prototype, {




  create: function create__1(resourceGroupName, zoneName, options, _) { var self, zone, progress, __this = this; var __frame = { name: "create__1", line: 39 }; return __func(_, this, arguments, create__1, 3, __frame, function __$create__1() { self = __this;

      zoneName = utils.trimTrailingChar(zoneName, ".");

      zone = {
        properties: { },
        location: constants.dnsZone.defLocation };

      zone = self._parseZone(zone, options);
      progress = self.interaction.progress(util.format($("Creating dns zone \"%s\""), zoneName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$create__1() {



            return self.dnsManagementClient.zones.createOrUpdate(resourceGroupName, zoneName, zone, options, __cb(_, __frame, 13, 44, function ___(__0, __1) { zone = __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() {

          self._showZone(zone, resourceGroupName, zoneName); _(); }); }); }); },


  set: function set__2(resourceGroupName, zoneName, options, _) { var self, zone, progress, __this = this; var __frame = { name: "set__2", line: 59 }; return __func(_, this, arguments, set__2, 3, __frame, function __$set__2() { self = __this;

      zoneName = utils.trimTrailingChar(zoneName, ".");

      return self.get(resourceGroupName, zoneName, __cb(_, __frame, 4, 20, function ___(__0, __1) { zone = __1;
        if (!zone) {
          return _(new Error(util.format($("A dns zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName))); } ;


        zone = self._parseZone(zone, options);

        progress = self.interaction.progress(util.format($("Updating dns zone \"%s\""), zoneName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$set__2() {



              return self.dnsManagementClient.zones.createOrUpdate(resourceGroupName, zoneName, zone, options, __cb(_, __frame, 15, 44, function ___(__0, __2) { zone = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$set__2() {

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


            self._showZone(zone, resourceGroupName, zoneName); _(); }); }); }, true)); }); },


  list: function list__3(options, _) { var self, progress, dnsZones, nextLink, nextZones, __this = this; var __frame = { name: "list__3", line: 82 }; return __func(_, this, arguments, list__3, 1, __frame, function __$list__3() { self = __this;

      progress = self.interaction.progress($("Getting the dns zones"));

      dnsZones = null; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$list__3() { return (function __$list__3(__then) {


              if (options.resourceGroup) {
                return self.dnsManagementClient.zones.listInResourceGroup(options.resourceGroup, options, __cb(_, __frame, 8, 50, function ___(__0, __1) { dnsZones = __1;
                  nextLink = dnsZones.nextLink; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$list__3() { __more = false;
                      var __6 = (nextLink !== undefined); if (__6) {
                        self.output.silly("Following nextLink");
                        return self.dnsManagementClient.zones.listInResourceGroupNext(nextLink, options, __cb(_, __frame, 12, 53, function ___(__0, __2) { nextZones = __2;
                          dnsZones.zones = dnsZones.concat(nextZones.zones);
                          nextLink = nextZones.nextLink; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); }, true)); } else {


                return self.dnsManagementClient.zones.listInSubscription(options, __cb(_, __frame, 17, 50, function ___(__0, __3) { dnsZones = __3;
                  nextLink = dnsZones.nextLink; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$list__3() { __more = false;
                      var __9 = (nextLink !== undefined); if (__9) {
                        self.output.silly("Following nextLink");
                        return self.dnsManagementClient.zones.listInSubscriptionNext(nextLink, options, __cb(_, __frame, 21, 53, function ___(__0, __4) { nextZones = __4;
                          dnsZones.zones = dnsZones.concat(nextZones.zones);
                          nextLink = nextZones.nextLink; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); }, true)); } ; })(function __$list__3() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$list__3() {



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


          self.interaction.formatOutput(dnsZones, function(zones) {
            if ((zones.length === 0)) {
              self.output.warn($("No dns zones found")); }
             else {
              self.output.table(zones, function(row, zone) {
                row.cell($("Name"), zone.name);
                var resInfo = resourceUtils.getResourceInformation(zone.id);
                row.cell($("Resource group"), resInfo.resourceGroup);
                row.cell($("Tags"), (tagUtils.getTagsInfo(zone.tags) || "")); }); } ; }); _(); }); }); }); },





  show: function show__4(resourceGroupName, zoneName, options, _) { var self, zone, __this = this; var __frame = { name: "show__4", line: 126 }; return __func(_, this, arguments, show__4, 3, __frame, function __$show__4() { self = __this;

      zoneName = utils.trimTrailingChar(zoneName, ".");

      return self.get(resourceGroupName, zoneName, __cb(_, __frame, 4, 20, function ___(__0, __1) { zone = __1;
        self._showZone(zone, resourceGroupName, zoneName); _(); }, true)); }); },


  clear: function clear__5(resourceGroupName, zoneName, options, _) { var self, recordSets, progress, i, recordSet, type, __this = this; var __frame = { name: "clear__5", line: 134 }; return __func(_, this, arguments, clear__5, 3, __frame, function __$clear__5() { self = __this;

      zoneName = utils.trimTrailingChar(zoneName, "."); return (function __$clear__5(_) {

        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Clear dns zone \"%s\"? [y/n] "), zoneName), __cb(_, __frame, 4, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -133, 17, function ___(__0, __2) { return (function __$clear__5(__then) { if (__2) {
            cli.output.info(util.format($("DNS zone \"%s\" was not cleared and still has old record set list"), zoneName)); return _(null); } else { __then(); } ; })(function __$clear__5() {



          recordSets = null;
          progress = self.interaction.progress($("Looking up the DNS Record Sets")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$clear__5() {

                return self.dnsManagementClient.recordSets.listAllInResourceGroup(resourceGroupName, zoneName, options, __cb(_, __frame, 12, 55, function ___(__0, __3) { recordSets = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$clear__5() {

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


              i = 0; var __7 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$clear__5() { __more = false; if (__7) { i++; } else { __7 = true; } ; var __6 = (i < recordSets.length); if (__6) {
                    recordSet = recordSets[i];
                    type = recordSetUtils.getShortType(recordSet.id);
                    if (((recordSet.name === "@") && (((type === constants.dnsZone.SOA) || (type === constants.dnsZone.NS))))) { while (__more) { __loop(); }; __more = true; return; } ;

                    options.type = type;
                    return self.deleteRecordSet(resourceGroupName, zoneName, recordSet.name, options, __cb(_, __frame, 23, 11, function __$clear__5() { while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(_); }); }); }); }, true)); }); },



  delete: function delete__6(resourceGroupName, zoneName, options, _) { var self, progress, response, __this = this; var __frame = { name: "delete__6", line: 161 }; return __func(_, this, arguments, delete__6, 3, __frame, function __$delete__6() { self = __this;

      zoneName = utils.trimTrailingChar(zoneName, ".");

      self.output.warn(util.format($("Deleting dns zone \"%s\" you will delete all record sets"), zoneName)); return (function __$delete__6(_) {
        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($(("WARNING: This will delete the DNS zone \"%s\" and all DNS records. " + "This operation cannot be undone. Please confirm [y/n]")), zoneName), __cb(_, __frame, 5, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -160, 17, function ___(__0, __2) { return (function __$delete__6(__then) { if (__2) {

            cli.output.info(util.format($("DNS zone \"%s\" was not deleted and still exists in resource group \"%s\""), zoneName, resourceGroupName)); return _(null); } else { __then(); } ; })(function __$delete__6() {



          progress = self.interaction.progress(util.format($("Deleting dns zone \"%s\""), zoneName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$delete__6() {


                return self.dnsManagementClient.zones.deleteMethod(resourceGroupName, zoneName, options, __cb(_, __frame, 14, 48, function ___(__0, __3) { response = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$delete__6() {

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


              if ((response.statusCode === 204)) {
                return _(new Error(util.format($("A dns zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName))); } ; _(); }); }); }); }, true)); }); },



  get: function get__7(resourceGroupName, zoneName, _) { var self, progress, dnsZone, __this = this; var __frame = { name: "get__7", line: 185 }; return __func(_, this, arguments, get__7, 2, __frame, function __$get__7() { self = __this;

      zoneName = utils.trimTrailingChar(zoneName, ".");
      progress = self.interaction.progress(util.format($("Looking up the dns zone \"%s\""), zoneName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$get__7() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$get__7() {

                  return self.dnsManagementClient.zones.get(resourceGroupName, zoneName, null, __cb(_, __frame, 5, 51, function ___(__0, __1) { dnsZone = __1;
                    return _(null, dnsZone); }, true)); }); })(function ___(e, __result) { __catch(function __$get__7() { if (e) {

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

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

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



  update: function update__8(resourceGroupName, zoneName, dnsZone, _) { var self, progress, __this = this; var __frame = { name: "update__8", line: 202 }; return __func(_, this, arguments, update__8, 3, __frame, function __$update__8() { self = __this;

      zoneName = utils.trimTrailingChar(zoneName, ".");
      progress = self.interaction.progress(util.format($("Updating dns zone \"%s\""), zoneName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$update__8() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$update__8() {

                  return self.dnsManagementClient.zones.createOrUpdate(resourceGroupName, zoneName, { zone: dnsZone }, __cb(_, __frame, 5, 37, __then, true)); }); })(function ___(e, __result) { __catch(function __$update__8() { if (e) {

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

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



  import: function import__9(resourceGroupName, zoneName, options, _) { var self, text, zfile, dnsZone, totalSetsCount, importedSetsCount, i, recordSet, __this = this; var __frame = { name: "import__9", line: 215 }; return __func(_, this, arguments, import__9, 3, __frame, function __$import__9() { self = __this;

      zoneName = zoneName.toLowerCase();

      if (options.debug) { console.time("Time elapsed"); } ;

      text = fs.readFileSync(options.fileName, "utf8");
      zfile = self.zoneFile.parse(zoneName, text);

      if ((options.parseOnly && self.output.format().json)) {
        self.output.json(zfile); } ;

      if (options.parseOnly) { return _(null); } ;

      return self.get(resourceGroupName, zoneName, __cb(_, __frame, 14, 23, function ___(__0, __1) { dnsZone = __1; return (function __$import__9(__then) {
          if (!dnsZone) {
            return self.create(resourceGroupName, zoneName, options, __cb(_, __frame, 16, 11, __then, true)); } else { __then(); } ; })(function __$import__9() {


          totalSetsCount = zfile.sets.length;
          importedSetsCount = 0;

          i = 0; var __6 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$import__9() { __more = false; if (__6) { i++; } else { __6 = true; } ; var __5 = (i < zfile.sets.length); if (__5) {
                recordSet = zfile.sets[i];
                return self.importRecordSet(resourceGroupName, zoneName, recordSet, options, __cb(_, __frame, 24, 32, function ___(__0, __2) { importedSetsCount += __2;
                  self.output.info(util.format($("%d record sets of %d imported"), importedSetsCount, totalSetsCount)); while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$import__9() {


            if (options.debug) { console.timeEnd("Time elapsed"); } ; _(); }); }); }, true)); }); },


  export: function export__10(resourceGroupName, zoneName, options, _) { var self, dnsZone, recordSets, nextLink, nextRecordSets, fileData, progress, __this = this; var __frame = { name: "export__10", line: 246 }; return __func(_, this, arguments, export__10, 3, __frame, function __$export__10() { self = __this;

      zoneName = zoneName.toLowerCase();
      zoneName = utils.trimTrailingChar(zoneName, "."); return (function __$export__10(__then) {

        if (fs.existsSync(options.fileName)) { return (function __$export__10(_) {
            var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Overwrite file \"%s\"? [y/n] "), options.fileName), __cb(_, __frame, 6, 46, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -245, 17, function ___(__0, __2) { return (function __$export__10(__then) { if (__2) {
                cli.output.info(util.format($("File \"%s\" was not overwritten"), options.fileName)); return _(null); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$export__10() {




        return self.get(resourceGroupName, zoneName, __cb(_, __frame, 12, 23, function ___(__0, __3) { dnsZone = __3;
          if (!dnsZone) {
            return _(new Error(util.format($("DNS zone \"%s\" not found in resource group \"%s\""), zoneName, resourceGroupName))); } ;

          return self.dnsManagementClient.recordSets.listAllInResourceGroup(resourceGroupName, zoneName, options, __cb(_, __frame, 16, 57, function ___(__0, __4) { recordSets = __4;

            nextLink = recordSets.nextLink; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$export__10() { __more = false;
                var __9 = (nextLink !== undefined); if (__9) {
                  self.output.silly("Following nextLink");
                  return self.dnsManagementClient.recordSets.listAllInResourceGroupNext(nextLink, __cb(_, __frame, 21, 63, function ___(__0, __5) { nextRecordSets = __5;
                    recordSets = recordSets.concat(nextRecordSets);
                    nextLink = nextRecordSets.nextLink; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$export__10() {


              fileData = self.zoneFile.generate(resourceGroupName, zoneName, recordSets);

              progress = self.interaction.progress(util.format($("Exporting dns zone \"%s\" from resource group \"%s\""), zoneName, resourceGroupName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$export__10() {

                    fs.writeFileSync(options.fileName, fileData); _(null, null, true); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$export__10() {

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






  importRecordSet: function importRecordSet__11(resourceGroupName, zoneName, recordSet, options, _) { var self, parameters, progress, res, existingSet, __this = this; var __frame = { name: "importRecordSet__11", line: 285 }; return __func(_, this, arguments, importRecordSet__11, 4, __frame, function __$importRecordSet__11() { self = __this;



      recordSet.name = self.zoneFile.covertFromFQDN(recordSet.name, zoneName);
      zoneName = utils.trimTrailingChar(zoneName, ".");


      if ((recordSet.name === "@")) {
        switch (recordSet.type) {


        case constants.dnsZone.SOA: self.output.info($("The \"host\" of the SOA record is determined by the Azure DNS name server names - the value specified in the imported zone file is ignored"));
          break;
        case constants.dnsZone.NS:


          self.output.info($("The authoritative NS records at the zone apex are determined by the Azure DNS name server names - the values specified in the imported zone file are ignored"));
          break;
        }; } ;




      parameters = recordSetUtils.covertToAzureFormat(recordSet);


      if (options.force) {
        parameters.ifNoneMatch = undefined; }
       else {
        parameters.ifNoneMatch = "*"; } ;






      progress = self.interaction.progress(util.format($("Importing record set \"%s\" of type \"%s\""), recordSet.name, recordSet.type));
      return self.tryImportRecordSet(resourceGroupName, zoneName, recordSet.name, recordSet.type, parameters, __cb(_, __frame, 38, 19, function ___(__0, __1) { res = __1; return (function __$importRecordSet__11(__then) {
          if ((res.statusCode === 412)) {
            return self.getRecordSet(resourceGroupName, zoneName, recordSet.name, recordSet, __cb(_, __frame, 40, 29, function ___(__0, __2) { existingSet = __2;
              parameters = recordSetUtils.merge(parameters, existingSet, recordSet.type, options, self.output);
              return self.tryImportRecordSet(resourceGroupName, zoneName, recordSet.name, recordSet.type, parameters, __cb(_, __frame, 42, 11, __then, true)); }, true)); } else { __then(); } ; })(function __$importRecordSet__11() {

          progress.end();

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


  tryImportRecordSet: function tryImportRecordSet__12(resourceGroupName, zoneName, setName, setType, parameters, _) { var self, res, __this = this; var __frame = { name: "tryImportRecordSet__12", line: 334 }; return __func(_, this, arguments, tryImportRecordSet__12, 5, __frame, function __$tryImportRecordSet__12() { self = __this;

      res = { }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$tryImportRecordSet__12() { return (function __$tryImportRecordSet__12(__then) {

              if (((setName === "@") && (((setType === constants.dnsZone.SOA) || (setType === constants.dnsZone.NS))))) {


                return self.dnsManagementClient.recordSets.update(resourceGroupName, zoneName, setName, setType, parameters, null, __cb(_, __frame, 7, 44, __then, true)); } else {



                return self.dnsManagementClient.recordSets.createOrUpdate(resourceGroupName, zoneName, setName, setType, parameters, null, __cb(_, __frame, 11, 44, __then, true)); } ; })(function __$tryImportRecordSet__12() {

              res.statusCode = 200; __then(); }); }); })(function ___(e, __result) { __catch(function __$tryImportRecordSet__12() { if (e) {

              res.statusCode = e.statusCode;
              if ((e.statusCode !== 412)) {
                self.output.warn(e.message); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$tryImportRecordSet__12() {


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


  createRecordSet: function createRecordSet__13(resourceGroupName, zoneName, setName, options, _) { var self, recordSet, progress, __this = this; var __frame = { name: "createRecordSet__13", line: 357 }; return __func(_, this, arguments, createRecordSet__13, 4, __frame, function __$createRecordSet__13() { self = __this;


      recordSet = self._initRecordSet(resourceGroupName, zoneName, setName, options);
      progress = self.interaction.progress(util.format($("Creating DNS record set \"%s\" of type \"%s\""), setName, options.type)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createRecordSet__13() {

            return self.dnsManagementClient.recordSets.createOrUpdate(resourceGroupName, zoneName, setName, options.type, recordSet, options, __cb(_, __frame, 6, 54, function ___(__0, __1) { recordSet = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$createRecordSet__13() {

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

          self._showRecordSet(recordSet); _(); }); }); }); },


  setRecordSet: function setRecordSet__14(resourceGroupName, zoneName, setName, options, _) { var self, zone, recordSet, __this = this; var __frame = { name: "setRecordSet__14", line: 370 }; return __func(_, this, arguments, setRecordSet__14, 4, __frame, function __$setRecordSet__14() { self = __this;

      options.type = utils.verifyParamExistsInCollection(constants.dnsZone.recordTypes, options.type, "--type");

      return self.get(resourceGroupName, zoneName, __cb(_, __frame, 4, 20, function ___(__0, __1) { zone = __1;
        if (!zone) {
          return _(new Error(util.format($("A DNS zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName))); } ;


        return self.getRecordSet(resourceGroupName, zoneName, setName, options, __cb(_, __frame, 9, 25, function ___(__0, __2) { recordSet = __2;
          if (!recordSet) {
            return _(new Error(util.format($("A record set with name \"%s\" of type \"%s\" not found in the DNS zone \"%s\""), setName, options.type, zoneName))); } ;


          self._parseRecordSet(recordSet, options, false);

          return self.updateRecordSet(resourceGroupName, zoneName, setName, options.type, recordSet, __cb(_, __frame, 16, 21, function ___(__0, __3) { recordSet = __3;
            self._showRecordSet(recordSet); _(); }, true)); }, true)); }, true)); }); },


  setSoaRecord: function setSoaRecord__15(resourceGroupName, zoneName, options, _) { var self, setName, recordSet, __this = this; var __frame = { name: "setSoaRecord__15", line: 390 }; return __func(_, this, arguments, setSoaRecord__15, 3, __frame, function __$setSoaRecord__15() { self = __this;



      setName = "@";
      options.type = constants.dnsZone.SOA;
      return self.getRecordSet(resourceGroupName, zoneName, setName, options, __cb(_, __frame, 6, 25, function ___(__0, __1) { recordSet = __1;
        if (!recordSet) {
          return _(new Error(util.format($("A record set with name \"%s\" of type \"%s\" not found in the DNS zone \"%s\""), setName, options.type, zoneName))); } ;

        if (options.email) {
          recordSet.soaRecord.email = options.email; } ;

        if (options.expireTime) {
          recordSet.soaRecord.expireTime = parseInt(options.expireTime); } ;

        if (options.serialNumber) {
          recordSet.soaRecord.serialNumber = parseInt(options.serialNumber); } ;

        if (options.minimumTtl) {
          recordSet.soaRecord.minimumTtl = parseInt(options.minimumTtl); } ;

        if (options.refreshTime) {
          recordSet.soaRecord.refreshTime = parseInt(options.refreshTime); } ;

        if (options.retryTime) {
          recordSet.soaRecord.retryTime = parseInt(options.retryTime); } ;

        self._parseRecordSet(recordSet, options, false);

        return self.updateRecordSet(resourceGroupName, zoneName, setName, options.type, recordSet, __cb(_, __frame, 30, 21, function ___(__0, __2) { recordSet = __2;
          self._showRecordSet(recordSet); _(); }, true)); }, true)); }); },


  deleteRecordSet: function deleteRecordSet__16(resourceGroupName, zoneName, setName, options, _) { var self, recordSet, progress, __this = this; var __frame = { name: "deleteRecordSet__16", line: 424 }; return __func(_, this, arguments, deleteRecordSet__16, 4, __frame, function __$deleteRecordSet__16() { self = __this;

      return self.getRecordSet(resourceGroupName, zoneName, setName, options, __cb(_, __frame, 2, 25, function ___(__0, __2) { recordSet = __2;
        if (!recordSet) {
          return _(new Error(util.format($("A record set with name \"%s\" of type \"%s\" not found in the DNS zone \"%s\""), setName, options.type, zoneName))); } ; return (function __$deleteRecordSet__16(_) {


          var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($("Delete DNS record set \"%s\" from DNS zone \"%s\"? [y/n] "), setName, zoneName), __cb(_, __frame, 7, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -423, 17, function ___(__0, __3) { return (function __$deleteRecordSet__16(__then) { if (__3) {
              cli.output.info(util.format($("DNS record set \"%s\" was not deleted and still exists in DNS zone \"%s\""), setName, zoneName)); return _(null); } else { __then(); } ; })(function __$deleteRecordSet__16() {



            progress = self.interaction.progress(util.format($("Deleting DNS record set \"%s\" of type \"%s\""), setName, options.type)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteRecordSet__16() {

                  return self.dnsManagementClient.recordSets.deleteMethod(resourceGroupName, zoneName, setName, options.type, options, __cb(_, __frame, 14, 42, function __$deleteRecordSet__16() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteRecordSet__16() {

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



  listRecordSets: function listRecordSets__17(resourceGroupName, zoneName, options, _) { var self, dnsRecords, progress, nextLink, nextRecordSets, __this = this; var __frame = { name: "listRecordSets__17", line: 444 }; return __func(_, this, arguments, listRecordSets__17, 3, __frame, function __$listRecordSets__17() { self = __this;

      dnsRecords = null;

      progress = self.interaction.progress($("Looking up the DNS Record Sets")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listRecordSets__17() { return (function __$listRecordSets__17(__then) {

              if (options.type) {
                options.type = self._validateType(options.type);
                return self.dnsManagementClient.recordSets.listByType(resourceGroupName, zoneName, options.type, options, __cb(_, __frame, 8, 57, function ___(__0, __1) { dnsRecords = __1; __then(); }, true)); } else {

                return self.dnsManagementClient.recordSets.listAllInResourceGroup(resourceGroupName, zoneName, options, __cb(_, __frame, 10, 57, function ___(__0, __2) { dnsRecords = __2; __then(); }, true)); } ; })(function __$listRecordSets__17() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listRecordSets__17() {


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


          nextLink = dnsRecords.nextLink; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$listRecordSets__17() { __more = false;
              var __6 = (nextLink !== undefined); if (__6) {
                self.output.silly("Following nextLink");
                return self.dnsManagementClient.recordSets.listByTypeNext(nextLink, __cb(_, __frame, 19, 63, function ___(__0, __3) { nextRecordSets = __3;
                  dnsRecords = dnsRecords.concat(nextRecordSets);
                  nextLink = nextRecordSets.nextLink; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$listRecordSets__17() {

            self.interaction.formatOutput(dnsRecords, function(outputData) {
              if ((outputData.length === 0)) {
                self.output.warn($("No DNS records sets found")); }
               else {
                var indent = 2;
                var formattedRecordSetList = recordSetUtils.convertToListFormat(outputData);
                formattedRecordSetList.forEach(function(recordSet) {
                  self.output.nameValue($("Name"), recordSet.name);
                  self.output.nameValue($("Type"), recordSet.type);
                  self.output.nameValue($("TTL"), recordSet.ttl);
                  self.output.nameValue($("Email"), recordSet.email);
                  self.output.nameValue($("Host"), recordSet.host);
                  self.output.nameValue($("Serial Number"), recordSet.serialNumber);
                  self.output.nameValue($("Refresh Time"), recordSet.refreshTime);
                  self.output.nameValue($("Retry Time"), recordSet.retryTime);
                  self.output.nameValue($("Expire Time"), recordSet.expireTime);
                  self.output.nameValue($("Minimum TTL"), recordSet.minimumTtl);

                  if ((recordSet.records && (recordSet.records.length > 0))) {
                    self.output.header($("Records"));
                    if ((recordSet.type === constants.dnsZone.TXT)) {
                      recordSet.records.forEach(function(item) {
                        item = item.join("");
                        item = recordSetUtils.displaySpecialCharacters(item);
                        self.output.data(util.format($("%s\"%s\""), self.output.spaces(indent), item)); }); }

                     else {
                      self.output.list(recordSet.records, indent); } ; } ;


                  if (recordSet.record) {
                    self.output.nameValue($("Record"), recordSet.record); } ;

                  self.output.data($(""), ""); }); } ; }); _(); }); }); }); }); },





  getRecordSet: function getRecordSet__18(resourceGroupName, zoneName, setName, options, _) { var self, progress, recordSet, __this = this; var __frame = { name: "getRecordSet__18", line: 506 }; return __func(_, this, arguments, getRecordSet__18, 4, __frame, function __$getRecordSet__18() { self = __this;


      progress = self.interaction.progress(util.format($("Looking up the DNS Record Set \"%s\" of type \"%s\""), setName, options.type)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getRecordSet__18() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getRecordSet__18() {

                  options.type = options.type.toUpperCase();
                  return self.dnsManagementClient.recordSets.get(resourceGroupName, zoneName, setName, options.type, __cb(_, __frame, 6, 58, function ___(__0, __1) { recordSet = __1;
                    recordSetUtils.removeEmptyRecords(recordSet);
                    return _(null, recordSet); }, true)); }); })(function ___(e, __result) { __catch(function __$getRecordSet__18() { if (e) {

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

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

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



  showRecordSet: function showRecordSet__19(resourceGroupName, zoneName, setName, options, _) { var self, recordSet, __this = this; var __frame = { name: "showRecordSet__19", line: 525 }; return __func(_, this, arguments, showRecordSet__19, 4, __frame, function __$showRecordSet__19() { self = __this;

      options.type = utils.verifyParamExistsInCollection(constants.dnsZone.recordTypes, options.type, "--type");

      return self.getRecordSet(resourceGroupName, zoneName, setName, options, __cb(_, __frame, 4, 25, function ___(__0, __1) { recordSet = __1;
        self.interaction.formatOutput(recordSet, function(recordSet) {
          if ((recordSet === null)) {
            self.output.warn(util.format($("A DNS record with name \"%s\" not found in the zone \"%s\""), setName, zoneName)); }
           else {
            self._showRecordSet(recordSet); } ; }); _(); }, true)); }); },




  addRecord: function addRecord__20(resourceGroupName, zoneName, setName, options, _) { var self, dnsZone, recordSet, __this = this; var __frame = { name: "addRecord__20", line: 539 }; return __func(_, this, arguments, addRecord__20, 4, __frame, function __$addRecord__20() { self = __this;

      options.type = self._validateType(options.type);

      return self.get(resourceGroupName, zoneName, __cb(_, __frame, 4, 23, function ___(__0, __2) { dnsZone = __2;
        if (!dnsZone) {
          return _(new Error(util.format($("A DNS zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName))); } ;


        return self.getRecordSet(resourceGroupName, zoneName, setName, options, __cb(_, __frame, 9, 25, function ___(__0, __3) { recordSet = __3; return (function __$addRecord__20(__then) {
            if (recordSet) { return (function __$addRecord__20(_) {
                var __1 = (((options.type === constants.dnsZone.CNAME) && !options.quiet) && recordSet.cnameRecord); if (!__1) { return _(null, __1); } ; return self.interaction.confirm(util.format($(("The DNS record set with type \"%s\" permits only one record per record set." + "Do you want to replace the existing record set value to new \"%s\"? [y/n]")), options.type, options.cname), __cb(_, __frame, 11, 115, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -538, 17, function ___(__0, __4) { return (function __$addRecord__20(__then) { if (__4) {


                    cli.output.info(util.format($("DNS record set \"%s\" was not changed and still has value \"%s\""), setName, recordSet.cnameRecord.cname)); return _(null); } else { __then(); } ; })(__then); }, true)); } else {



              recordSet = self._initRecordSet(resourceGroupName, zoneName, setName, options); __then(); } ; })(function __$addRecord__20() {

            self._parseRecord(recordSet, options, true);
            return self.updateRecordSet(resourceGroupName, zoneName, setName, options.type, recordSet, __cb(_, __frame, 21, 21, function ___(__0, __5) { recordSet = __5;
              self._showRecordSet(recordSet); _(); }, true)); }); }, true)); }, true)); }); },


  deleteRecord: function deleteRecord__21(resourceGroupName, zoneName, setName, options, _) { var self, dnsZone, recordSet, recordCount, __this = this; var __frame = { name: "deleteRecord__21", line: 564 }; return __func(_, this, arguments, deleteRecord__21, 4, __frame, function __$deleteRecord__21() { self = __this;

      options.type = self._validateType(options.type);

      return self.get(resourceGroupName, zoneName, __cb(_, __frame, 4, 23, function ___(__0, __2) { dnsZone = __2;
        if (!dnsZone) {
          return _(new Error(util.format($("A DNS zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName))); } ;


        return self.getRecordSet(resourceGroupName, zoneName, setName, options, __cb(_, __frame, 9, 25, function ___(__0, __3) { recordSet = __3;
          if (!recordSet) {
            return _(new Error(util.format($("A record set with name \"%s\" of type \"%s\" not found in DNS zone \"%s\""), setName, options.type, zoneName))); } ;

          recordCount = self._parseRecord(recordSet, options, false); return (function __$deleteRecord__21(_) {

            var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return self.interaction.confirm($("Delete DNS Record? [y/n] "), __cb(_, __frame, 15, 44, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -563, 17, function ___(__0, __4) { return (function __$deleteRecord__21(__then) { if (__4) {
                cli.output.info(util.format($("DNS record was not deleted and still exists in record set \"%s\""), setName)); return _(null); } else { __then(); } ; })(function __$deleteRecord__21() { return (function __$deleteRecord__21(__then) {



                if (((recordCount === 0) && !options.keepEmptyRecordSet)) {
                  self.output.warn(util.format($("Record set \"%s\" of type \"%s\" will be deleted as well"), setName, options.type));
                  options.quiet = true;
                  return self.deleteRecordSet(resourceGroupName, zoneName, setName, options, __cb(_, __frame, 23, 11, __then, true)); } else {

                  return self.updateRecordSet(resourceGroupName, zoneName, setName, options.type, recordSet, __cb(_, __frame, 25, 23, function ___(__0, __5) { recordSet = __5;
                    self._showRecordSet(recordSet); __then(); }, true)); } ; })(_); }); }, true)); }, true)); }, true)); }); },



  updateRecordSet: function updateRecordSet__22(resourceGroupName, zoneName, setName, setType, parameters, _) { var self, progress, recordSet, __this = this; var __frame = { name: "updateRecordSet__22", line: 594 }; return __func(_, this, arguments, updateRecordSet__22, 5, __frame, function __$updateRecordSet__22() { self = __this;

      progress = self.interaction.progress(util.format($("Updating record set \"%s\" of type \"%s\""), setName, setType)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$updateRecordSet__22() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$updateRecordSet__22() {

                  return self.dnsManagementClient.recordSets.createOrUpdate(resourceGroupName, zoneName, setName, setType, parameters, __cb(_, __frame, 4, 58, function ___(__0, __1) { recordSet = __1;
                    return _(null, recordSet); }, true)); }); })(function ___(e, __result) { __catch(function __$updateRecordSet__22() { if (e) {

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

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

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



  promptRecordParamsIfNotGiven: function promptRecordParamsIfNotGiven__23(options, _) { var self, __this = this; var __frame = { name: "promptRecordParamsIfNotGiven__23", line: 610 }; return __func(_, this, arguments, promptRecordParamsIfNotGiven__23, 1, __frame, function __$promptRecordParamsIfNotGiven__23() { self = __this;

      options.type = self._validateType(options.type); return (function __$promptRecordParamsIfNotGiven__23(__break) {

        switch (options.type) {
        case constants.dnsZone.A: return self.interaction.promptIfNotGiven($("IPv4 address for A record: "), options.ipv4Address, __cb(_, __frame, 6, 47, function ___(__0, __1) {
            options.ipv4Address = __1; return __break(); }, true));

        case constants.dnsZone.AAAA: return self.interaction.promptIfNotGiven($("IPv6 address for AAAA record: "), options.ipv6Address, __cb(_, __frame, 9, 47, function ___(__0, __2) {
            options.ipv6Address = __2; return __break(); }, true));

        case constants.dnsZone.CNAME: return self.interaction.promptIfNotGiven($("Canonical name for CNAME record: "), options.cname, __cb(_, __frame, 12, 41, function ___(__0, __3) {
            options.cname = __3; return __break(); }, true));

        case constants.dnsZone.MX: return self.interaction.promptIfNotGiven($("Preference for MX record: "), options.preference, __cb(_, __frame, 15, 46, function ___(__0, __4) {
            options.preference = __4; return self.interaction.promptIfNotGiven($("Exchange for MX record: "), options.exchange, __cb(_, __frame, 16, 44, function ___(__0, __5) {
              options.exchange = __5; return __break(); }, true)); }, true));

        case constants.dnsZone.NS: return self.interaction.promptIfNotGiven($("Domain name for NS record: "), options.nsdname, __cb(_, __frame, 19, 43, function ___(__0, __6) {
            options.nsdname = __6; return __break(); }, true));

        case constants.dnsZone.SRV: return self.interaction.promptIfNotGiven($("Priority for SRV record: "), options.priority, __cb(_, __frame, 22, 44, function ___(__0, __7) {
            options.priority = __7; return self.interaction.promptIfNotGiven($("Weight for SRV record: "), options.weight, __cb(_, __frame, 23, 42, function ___(__0, __8) {
              options.weight = __8; return self.interaction.promptIfNotGiven($("Port for SRV record: "), options.port, __cb(_, __frame, 24, 40, function ___(__0, __9) {
                options.port = __9; return self.interaction.promptIfNotGiven($("Target for SRV record: "), options.target, __cb(_, __frame, 25, 42, function ___(__0, __10) {
                  options.target = __10; return __break(); }, true)); }, true)); }, true)); }, true));

        case constants.dnsZone.TXT: return self.interaction.promptIfNotGiven($("Text for TXT record type: "), options.text, __cb(_, __frame, 28, 40, function ___(__0, __11) {
            options.text = __11; return __break(); }, true));

        case constants.dnsZone.PTR: return self.interaction.promptIfNotGiven($("PTR domain name for PTR record: "), options.ptrdname, __cb(_, __frame, 31, 44, function ___(__0, __12) {
            options.ptrdname = __12; return __break(); }, true)); default:

          return __break(); }; })(_); }); },








  _initRecordSet: function(resourceGroupName, zoneName, setName, options) {
    var self = this;

    options.type = utils.verifyParamExistsInCollection(constants.dnsZone.recordTypes, options.type, "--type");
    if ((options.type === constants.dnsZone.SOA)) {
      throw new Error(util.format($("Only one \"%s\" record is allowed in dns zone"), options.type)); } ;


    var recordSet = { };
    var propName = recordSetUtils.getPropertyName(options.type);
    recordSet[propName] = [];

    self._parseRecordSet(recordSet, options, true);
    return recordSet; },


  _parseZone: function(zone, options) {
    if (options.tags) {
      if (utils.argHasValue(options.tags)) {
        tagUtils.appendTags(zone, options); }
       else {
        zone.tags = { }; } ; } ;


    return zone; },


  _parseRecordSet: function(recordSet, options, useDefaults) {
    var self = this;

    if (options.ttl) {
      var ttlAsInt = utils.parseInt(options.ttl);
      if ((isNaN(ttlAsInt) || ((ttlAsInt < 0)))) {
        throw new Error($("--ttl value must be positive integer")); } ;

      recordSet.tTL = ttlAsInt; }
     else if (useDefaults) {
      var defTtl = constants.dnsZone.defTtl;
      self.output.warn(util.format($("using default TTL of %s seconds"), defTtl));
      recordSet.tTL = defTtl; }  ;


    if (options.metadata) {
      if (utils.argHasValue(options.metadata)) {
        tagUtils.appendTags(recordSet, options, "metadata"); }
       else {
        recordSet.metadata = { }; } ; } ; },




  _parseRecord: function(recordSet, options, isAdding) {
    var self = this;
    var recordIndex;
    var recordCount = 0;


    if (options.ipv4Address) {
      if ((options.type !== constants.dnsZone.A)) {
        self.output.info(util.format($("--ipv4-address will be ignored for record of type \"%s\""), options.type)); }
       else {
        if (isAdding) {
          recordSet.aRecords.push({ ipv4Address: options.ipv4Address }); }
         else {
          recordIndex = utils.indexOfCaseIgnore(recordSet.aRecords, { ipv4Address: options.ipv4Address });
          if ((recordIndex === -1)) {
            throw new Error(util.format($("Record of type \"%s\" with IPv4 \"%s\" not found in the record set \"%s\""), options.type, options.ipv4Address, recordSet.name)); } ;

          recordSet.aRecords.splice(recordIndex, 1);
          recordCount = recordSet.aRecords.length; } ; } ; } ;





    if (options.ipv6Address) {
      if ((options.type !== constants.dnsZone.AAAA)) {
        self.output.info(util.format($("--ipv6-address will be ignored for record of type \"%s\""), options.type)); }
       else {
        if (isAdding) {
          recordSet.aaaaRecords.push({ ipv6Address: options.ipv6Address }); }
         else {
          recordIndex = utils.indexOfCaseIgnore(recordSet.aaaaRecords, { ipv6Address: options.ipv6Address });
          if ((recordIndex === -1)) {
            throw new Error(util.format($("Record of type \"%s\" with IPv6 \"%s\" not found in the record set \"%s\""), options.type, options.ipv6Address, recordSet.name)); } ;

          recordSet.aaaaRecords.splice(recordIndex, 1);
          recordCount = recordSet.aaaaRecords.length; } ; } ; } ;





    if (options.cname) {
      if ((options.type !== constants.dnsZone.CNAME)) {
        self.output.info(util.format($("--cname will be ignored for record of type \"%s\""), options.type)); }
       else {
        if (isAdding) {
          options.cname = utils.trimTrailingChar(options.cname, ".");
          recordSet.cnameRecord = { cname: options.cname }; }
         else {
          if ((recordSet.cnameRecord.cname === options.cname)) {
            delete recordSet.cnameRecord; }
           else {
            throw new Error(util.format($("Record of type \"%s\" with cname \"%s\" not found in the record set \"%s\""), options.type, options.cname, recordSet.name)); } ; } ; } ; } ;






    if ((options.preference || options.exchange)) {
      if ((options.type !== constants.dnsZone.MX)) {
        self.output.info(util.format($("--preference,--exchange will be ignored for record of type \"%s\""), options.type)); }
       else {
        options.exchange = utils.trimTrailingChar(options.exchange, ".");
        options.preference = parseInt(options.preference);
        if (isAdding) {
          recordSet.mxRecords.push({ preference: options.preference, exchange: options.exchange }); }
         else {
          recordIndex = utils.indexOfCaseIgnore(recordSet.mxRecords, { preference: options.preference, exchange: options.exchange });
          if ((recordIndex === -1)) {
            throw new Error(util.format($("Record of type \"%s\" with preference \"%s\" and exchange \"%s\" not found in the record set \"%s\""), options.type, options.preference, options.exchange, recordSet.name)); } ;

          recordSet.mxRecords.splice(recordIndex, 1);
          recordCount = recordSet.mxRecords.length; } ; } ; } ;





    if (options.nsdname) {
      if ((options.type !== constants.dnsZone.NS)) {
        self.output.info(util.format($("--nsdname will be ignored for record of type \"%s\""), options.type)); }
       else {
        if (isAdding) {
          recordSet.nsRecords.push({ nsdname: options.nsdname }); }
         else {
          recordIndex = utils.indexOfCaseIgnore(recordSet.nsRecords, { nsdname: options.nsdname });
          if ((recordIndex === -1)) {
            throw new Error(util.format($("Record of type \"%s\" with nsdname \"%s\" not found in the record set \"%s\""), options.type, options.nsdname, recordSet.name)); } ;

          recordSet.nsRecords.splice(recordIndex, 1);
          recordCount = recordSet.nsRecords.length; } ; } ; } ;





    if ((options.type.toUpperCase() !== constants.dnsZone.SOA)) {
      if ((((((options.email || options.expireTime) || options.host) || options.minimumTtl) || options.refreshTime) || options.retryTime)) {
        self.output.info(util.format($("SOA parameters will be ignored due to type of this DNS record - \"%s\""), options.type)); } ; }

     else if ((((((options.email || options.expireTime) || options.host) || options.minimumTtl) || options.refreshTime) || options.retryTime)) {
      if ((((((options.email && options.expireTime) && options.host) && options.minimumTtl) && options.refreshTime) && options.retryTime)) {
        throw new Error($("You must specify all SOA parameters if even one is specified")); } ;


      if ((isNaN(options.expireTime) || (options.expireTime < 0))) {
        throw new Error($("--expire-time parameter must be positive integer")); } ;


      if ((isNaN(options.refreshTime) || (options.refreshTime < 0))) {
        throw new Error($("--refresh-time parameter must be positive integer")); } ;


      if ((isNaN(options.retryTime) || (options.retryTime < 0))) {
        throw new Error($("--retry-time parameter must be positive integer")); } ;


      if ((isNaN(options.minimumTtl) || (options.minimumTtl < 255))) {
        throw new Error($("--minimumTtl parameter must be in the range [0,255]")); } ;


      if (true) {
        recordSet.soaRecord = {
          email: options.email,
          expireTime: options.expireTime,

          minimumTtl: options.minumumTtl,
          refreshTime: options.refreshTime,
          retryTime: options.retryTime }; }

       else {
        var soaRecord = ((((((((recordSet.soaRecord.email === options.email)) && ((recordSet.soaRecord.expireTime === parseInt(options.expireTime)))) && ((recordSet.soaRecord.host === options.host))) && ((recordSet.soaRecord.minimumTtl === parseInt(options.minimumTtl)))) && ((recordSet.soaRecord.refreshTime === parseInt(options.refreshTime)))) && ((recordSet.soaRecord.retryTime === parseInt(options.retryTime)))));

        if (!soaRecord) {
          self.output.warn($("Record SOA not found in the record set with parameters specified.")); }
         else {
          delete recordSet.soaRecord; } ; } ; }  ;





    if ((((options.priority || options.weight) || options.port) || options.target)) {
      if ((options.type !== constants.dnsZone.SRV)) {
        self.output.info(util.format($("--priority,--weight,--port,--target will be ignored for record of type \"%s\""), options.type)); }
       else {
        options.target = utils.trimTrailingChar(options.target, ".");
        options.priority = parseInt(options.priority);
        options.weight = parseInt(options.weight);
        options.port = parseInt(options.port);
        if (isAdding) {
          recordSet.srvRecords.push({
            priority: options.priority,
            weight: options.weight,
            port: options.port,
            target: options.target }); }

         else {
          recordIndex = utils.indexOfCaseIgnore(recordSet.srvRecords, {
            priority: options.priority,
            weight: options.weight,
            port: options.port,
            target: options.target });

          if ((recordIndex === -1)) {
            throw new Error(util.format($("Record of type \"%s\" with priority=\"%s\",weight=\"%s\",port=\"%s\",target=\"%s\" not found in the record set \"%s\""), options.type, options.priority, options.weight, options.port, options.target, recordSet.name)); } ;


          recordSet.srvRecords.splice(recordIndex, 1);
          recordCount = recordSet.srvRecords.length; } ; } ; } ;





    if (options.text) {
      if ((options.type !== constants.dnsZone.TXT)) {
        self.output.info(util.format($("--text will be ignored for record of type \"%s\""), options.type)); }
       else {
        var textArray = recordSetUtils.splitTxtRecord(options.text);
        if (isAdding) {
          recordSet.txtRecords.push({ value: textArray }); }
         else {
          for (var record in recordSet.txtRecords) {
            recordSet.txtRecords[record].txtConcatenatedRecords = recordSet.txtRecords[record].value.join(""); };

          recordIndex = utils.indexOfCaseIgnore(recordSet.txtRecords, { txtConcatenatedRecords: options.text });
          if ((recordIndex === -1)) {
            throw new Error(util.format($("Record of type \"%s\" with value \"%s\" not found in the record set \"%s\""), options.type, options.text, recordSet.name)); } ;

          recordSet.txtRecords.splice(recordIndex, 1);
          recordCount = recordSet.txtRecords.length; } ; } ; } ;





    if (options.ptrdname) {
      if ((options.type !== constants.dnsZone.PTR)) {
        self.output.info(util.format($("--ptrd-name will be ignored for record of type \"%s\""), options.type)); }
       else {
        if (isAdding) {
          options.ptrdname = utils.trimTrailingChar(options.ptrdname, ".");
          recordSet.ptrRecords.push({ ptrdname: options.ptrdname }); }
         else {
          recordIndex = utils.indexOfCaseIgnore(recordSet.ptrRecords, { ptrdname: options.ptrdname });
          if ((recordIndex === -1)) {
            throw new Error(util.format($("Record of type \"%s\" with pointer domain name \"%s\" not found in the record set \"%s\""), options.type, options.ptrdname, recordSet.name)); } ;

          recordSet.ptrRecords.splice(recordIndex, 1);
          recordCount = recordSet.ptrRecords.length; } ; } ; } ;



    return recordCount; },


  _showZone: function(zone, resourceGroupName, zoneName) {
    var self = this;
    var indent = 4;
    self.interaction.formatOutput(zone, function(zone) {
      if ((zone === null)) {
        self.output.warn(util.format($("A dns zone with name \"%s\" not found in the resource group \"%s\""), zoneName, resourceGroupName));
        return; } ;


      self.output.nameValue($("Id"), zone.id);
      self.output.nameValue($("Name"), zone.name);
      self.output.nameValue($("Type"), zone.type);
      self.output.nameValue($("Location"), zone.location);
      self.output.nameValue($("Number of record sets"), zone.numberOfRecordSets);
      self.output.nameValue($("Max number of record sets"), zone.maxNumberOfRecordSets);
      if ((zone.nameServers.length > 0)) {
        self.output.header($("Name servers"));
        self.output.list(zone.nameServers, indent); } ;

      self.output.nameValue($("Tags"), (tagUtils.getTagsInfo(zone.tags) || "")); }); },



  _showRecordSet: function(recordSet) {
    var self = this;
    self.interaction.formatOutput(recordSet, function(recordSet) {
      self.output.nameValue($("Id"), recordSet.id);
      self.output.nameValue($("Name"), recordSet.name);
      self.output.nameValue($("Type"), recordSet.type);
      self.output.nameValue($("TTL"), recordSet.tTL);
      self.output.nameValue($("Metadata"), (tagUtils.getTagsInfo(recordSet.metadata) || ""));
      if (!__.isEmpty(recordSet.aRecords)) {
        self.output.header($("A records"));
        for (var aRecordNum in recordSet.aRecords) {
          var aRecord = recordSet.aRecords[aRecordNum];
          self.output.nameValue($("IPv4 address"), aRecord.ipv4Address, 4); };

        self.output.data($(""), ""); } ;

      if (!__.isEmpty(recordSet.aaaaRecords)) {
        self.output.header($("AAAA records"));
        for (var aaaaRecordNum in recordSet.aaaaRecords) {
          var aaaaRecord = recordSet.aaaaRecords[aaaaRecordNum];
          self.output.nameValue($("IPv6 address"), aaaaRecord.ipv6Address, 4); };

        self.output.data($(""), ""); } ;

      if (!__.isEmpty(recordSet.cnameRecord)) {
        self.output.header($("CNAME record"));
        self.output.nameValue($("CNAME"), recordSet.cnameRecord.cname, 2);
        self.output.data($(""), ""); } ;

      if (!__.isEmpty(recordSet.mxRecords)) {
        self.output.header($("MX records"));
        for (var mxRecordNum in recordSet.mxRecords) {
          var mxRecord = recordSet.mxRecords[mxRecordNum];
          self.output.nameValue($("Preference"), mxRecord.preference, 4);
          self.output.nameValue($("Mail exchange"), mxRecord.exchange, 4); };

        self.output.data($(""), ""); } ;

      if (!__.isEmpty(recordSet.nsRecords)) {
        self.output.data($("NS records"));
        for (var nsRecordNum in recordSet.nsRecords) {
          var nsRecord = recordSet.nsRecords[nsRecordNum];
          self.output.nameValue($("Name server domain name"), nsRecord.nsdname, 4); };

        self.output.data($(""), ""); } ;

      if (!__.isEmpty(recordSet.srvRecords)) {
        self.output.header($("SRV records"));
        for (var srvRecordNum in recordSet.srvRecords) {
          var srvRecord = recordSet.srvRecords[srvRecordNum];
          self.output.nameValue($("Priority"), srvRecord.priority, 4);
          self.output.nameValue($("Weight"), srvRecord.weight, 4);
          self.output.nameValue($("Port"), srvRecord.port, 4);
          self.output.nameValue($("Target"), srvRecord.target, 4); };

        self.output.data($(""), ""); } ;

      if (!__.isEmpty(recordSet.txtRecords)) {
        self.output.header($("TXT records"));
        for (var txtRecordNum in recordSet.txtRecords) {
          var txtRecord = recordSet.txtRecords[txtRecordNum];
          var recordValue = txtRecord.value.join("");
          recordValue = recordSetUtils.displaySpecialCharacters(recordValue);
          self.output.nameValue($("Text"), util.format($("\"%s\""), recordValue), 4); };

        self.output.data($(""), ""); } ;

      if (!__.isEmpty(recordSet.soaRecord)) {
        var soaRecord = recordSet.soaRecord;
        self.output.header($("SOA record"));
        self.output.nameValue($("Email"), soaRecord.email, 2);
        self.output.nameValue($("Expire time"), soaRecord.expireTime, 2);
        self.output.nameValue($("Host"), soaRecord.host, 2);
        self.output.nameValue($("Serial number"), soaRecord.serialNumber, 2);
        self.output.nameValue($("Minimum TTL"), soaRecord.minimumTtl, 2);
        self.output.nameValue($("Refresh time"), soaRecord.refreshTime, 2);
        self.output.nameValue($("Retry time"), soaRecord.retryTime, 2);
        self.output.nameValue($(""), ""); } ;

      if (!__.isEmpty(recordSet.ptrRecords)) {
        self.output.header($("PTR records"));
        for (var ptrRecordNum in recordSet.ptrRecords) {
          var ptrRecord = recordSet.ptrRecords[ptrRecordNum];
          self.output.nameValue($("PTR domain name"), ptrRecord.ptrdname, 4);
          self.output.data($(""), ""); }; } ; }); },





  _validateType: function(type) {
    return utils.verifyParamExistsInCollection(constants.dnsZone.restrictedRecordTypes, type, "--type"); }});



module.exports = DnsZone;
