/* jshint latedef:false */
/* jshint forin:false */
/* jshint noempty:false */

// 
// Copyright (c) Microsoft and contributors.  All rights reserved.
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//   http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 
// See the License for the specific language governing permissions and
// limitations under the License.
// 

// Warning: This code was generated by a tool.
// 
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

'use strict';

var util = require('util');
var moment = require('moment');
var azureCommon = require('azure-common');
var Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;

var AutoscaleClient = ( /** @lends AutoscaleClient */ function() {
  /**
   * @class
   * Initializes a new instance of the AutoscaleClient class.
   * @constructor
   * 
   * @param {SubscriptionCloudCredentials} credentials Gets subscription
   * credentials which uniquely identify Microsoft Azure subscription. The
   * subscription ID forms part of the URI for every service call.
   * 
   * @param {string} [credentials.subscriptionId]
   * 
   * @param {string} [baseUri] Gets the URI used as the base for all cloud
   * service requests.
   * 
   * @param {Array} filters
   */
  function AutoscaleClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    AutoscaleClient['super_'].call(this, credentials, filters);
    
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = 'https://management.core.windows.net';
    }
    if (this.apiVersion === null || this.apiVersion === undefined) {
      this.apiVersion = '2013-10-01';
    }
    if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
      this.longRunningOperationInitialTimeout = -1;
    }
    if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
      this.longRunningOperationRetryTimeout = -1;
    }
    /**
     * Provides an instance of the [SettingOperations](-SettingOperations.html)
     * object.
     * @type {object}
     */
    this.settings = new SettingOperations(this);
  }
  
  util.inherits(AutoscaleClient, Service);
  
  
  return AutoscaleClient;
})();
exports.AutoscaleClient = AutoscaleClient;

var SettingOperations = ( /** @lends SettingOperations */ function() {
  /**
   * @class
   * Operations for managing the autoscale settings.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [AutoscaleClient] {@link AutoscaleClient~AutoscaleClient}.
   * See [settings] {@link AutoscaleClient~AutoscaleClient#settings}.
   * Initializes a new instance of the SettingOperations class.
   * @constructor
   * 
   * @param {AutoscaleClient} client Reference to the service client.
   */
  function SettingOperations(client) {
    this.client = client;
  }
  
  /**
   * 
   * @param {string} resourceId The resource ID.
   * 
   * @param {AutoscaleSettingCreateOrUpdateParameters} parameters Parameters
   * supplied to the operation.
   * 
   * @param {AutoscaleSetting} [parameters.setting] The setting to create or
   * update.
   * 
   * @param {array} [parameters.setting.profiles]
   * 
   * @param {boolean} [parameters.setting.enabled]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SettingOperations.prototype.createOrUpdate = function(resourceId, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceId === null || resourceId === undefined) {
      return callback(new Error('resourceId cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/monitoring/autoscalesettings';
    var queryParameters = [];
    queryParameters.push('resourceId=' + encodeURIComponent(resourceId));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.headers['x-ms-version'] = '2013-10-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var autoscaleSettingCreateOrUpdateParametersValue = {};
    requestDoc = autoscaleSettingCreateOrUpdateParametersValue;
    
    if (parameters.setting !== null && parameters.setting !== undefined) {
      if (parameters.setting.profiles !== null && parameters.setting.profiles !== undefined) {
        var profilesArray = [];
        for (var loweredIndex1 = 0; loweredIndex1 < parameters.setting.profiles.length; loweredIndex1 = loweredIndex1 + 1) {
          var profilesItem = parameters.setting.profiles[loweredIndex1];
          var autoscaleProfileValue = {};
          profilesArray.push(autoscaleProfileValue);
          
          if (profilesItem.name !== null && profilesItem.name !== undefined) {
            autoscaleProfileValue['Name'] = profilesItem.name;
          }
          
          if (profilesItem.capacity !== null && profilesItem.capacity !== undefined) {
            var capacityValue = {};
            autoscaleProfileValue['Capacity'] = capacityValue;
            
            if (profilesItem.capacity.minimum !== null && profilesItem.capacity.minimum !== undefined) {
              capacityValue['Minimum'] = profilesItem.capacity.minimum;
            }
            
            if (profilesItem.capacity.maximum !== null && profilesItem.capacity.maximum !== undefined) {
              capacityValue['Maximum'] = profilesItem.capacity.maximum;
            }
            
            if (profilesItem.capacity.default !== null && profilesItem.capacity.default !== undefined) {
              capacityValue['Default'] = profilesItem.capacity.default;
            }
          }
          
          if (profilesItem.rules !== null && profilesItem.rules !== undefined) {
            var rulesArray = [];
            for (var loweredIndex2 = 0; loweredIndex2 < profilesItem.rules.length; loweredIndex2 = loweredIndex2 + 1) {
              var rulesItem = profilesItem.rules[loweredIndex2];
              var scaleRuleValue = {};
              rulesArray.push(scaleRuleValue);
              
              if (rulesItem.metricTrigger !== null && rulesItem.metricTrigger !== undefined) {
                var metricTriggerValue = {};
                scaleRuleValue['MetricTrigger'] = metricTriggerValue;
                
                if (rulesItem.metricTrigger.metricName !== null && rulesItem.metricTrigger.metricName !== undefined) {
                  metricTriggerValue['MetricName'] = rulesItem.metricTrigger.metricName;
                }
                
                if (rulesItem.metricTrigger.metricNamespace !== null && rulesItem.metricTrigger.metricNamespace !== undefined) {
                  metricTriggerValue['MetricNamespace'] = rulesItem.metricTrigger.metricNamespace;
                }
                
                if (rulesItem.metricTrigger.metricSource !== null && rulesItem.metricTrigger.metricSource !== undefined) {
                  metricTriggerValue['MetricSource'] = rulesItem.metricTrigger.metricSource;
                }
                
                if (rulesItem.metricTrigger.timeGrain !== null && rulesItem.metricTrigger.timeGrain !== undefined) {
                  metricTriggerValue['TimeGrain'] = rulesItem.metricTrigger.timeGrain.toIsoString();
                }
                
                if (rulesItem.metricTrigger.statistic !== null && rulesItem.metricTrigger.statistic !== undefined) {
                  metricTriggerValue['Statistic'] = rulesItem.metricTrigger.statistic !== null && rulesItem.metricTrigger.statistic !== undefined ? rulesItem.metricTrigger.statistic.toString() : 'Average';
                }
                
                if (rulesItem.metricTrigger.timeWindow !== null && rulesItem.metricTrigger.timeWindow !== undefined) {
                  metricTriggerValue['TimeWindow'] = rulesItem.metricTrigger.timeWindow.toIsoString();
                }
                
                if (rulesItem.metricTrigger.timeAggregation !== null && rulesItem.metricTrigger.timeAggregation !== undefined) {
                  metricTriggerValue['TimeAggregation'] = rulesItem.metricTrigger.timeAggregation !== null && rulesItem.metricTrigger.timeAggregation !== undefined ? rulesItem.metricTrigger.timeAggregation.toString() : 'Average';
                }
                
                if (rulesItem.metricTrigger.operator !== null && rulesItem.metricTrigger.operator !== undefined) {
                  metricTriggerValue['Operator'] = rulesItem.metricTrigger.operator !== null && rulesItem.metricTrigger.operator !== undefined ? rulesItem.metricTrigger.operator.toString() : 'Equals';
                }
                
                if (rulesItem.metricTrigger.threshold !== null && rulesItem.metricTrigger.threshold !== undefined) {
                  metricTriggerValue['Threshold'] = rulesItem.metricTrigger.threshold;
                }
              }
              
              if (rulesItem.scaleAction !== null && rulesItem.scaleAction !== undefined) {
                var scaleActionValue = {};
                scaleRuleValue['ScaleAction'] = scaleActionValue;
                
                if (rulesItem.scaleAction.direction !== null && rulesItem.scaleAction.direction !== undefined) {
                  scaleActionValue['Direction'] = rulesItem.scaleAction.direction !== null && rulesItem.scaleAction.direction !== undefined ? rulesItem.scaleAction.direction.toString() : 'None';
                }
                
                if (rulesItem.scaleAction.type !== null && rulesItem.scaleAction.type !== undefined) {
                  scaleActionValue['Type'] = rulesItem.scaleAction.type !== null && rulesItem.scaleAction.type !== undefined ? rulesItem.scaleAction.type.toString() : 'ChangeSize';
                }
                
                if (rulesItem.scaleAction.value !== null && rulesItem.scaleAction.value !== undefined) {
                  scaleActionValue['Value'] = rulesItem.scaleAction.value;
                }
                
                if (rulesItem.scaleAction.cooldown !== null && rulesItem.scaleAction.cooldown !== undefined) {
                  scaleActionValue['Cooldown'] = rulesItem.scaleAction.cooldown.toIsoString();
                }
              }
            }
            autoscaleProfileValue['Rules'] = rulesArray;
          }
          
          if (profilesItem.fixedDate !== null && profilesItem.fixedDate !== undefined) {
            var fixedDateValue = {};
            autoscaleProfileValue['FixedDate'] = fixedDateValue;
            
            if (profilesItem.fixedDate.timeZone !== null && profilesItem.fixedDate.timeZone !== undefined) {
              fixedDateValue['TimeZone'] = profilesItem.fixedDate.timeZone;
            }
            
            if (profilesItem.fixedDate.start !== null && profilesItem.fixedDate.start !== undefined) {
              fixedDateValue['Start'] = profilesItem.fixedDate.start;
            }
            
            if (profilesItem.fixedDate.end !== null && profilesItem.fixedDate.end !== undefined) {
              fixedDateValue['End'] = profilesItem.fixedDate.end;
            }
          }
          
          if (profilesItem.recurrence !== null && profilesItem.recurrence !== undefined) {
            var recurrenceValue = {};
            autoscaleProfileValue['Recurrence'] = recurrenceValue;
            
            if (profilesItem.recurrence.frequency !== null && profilesItem.recurrence.frequency !== undefined) {
              recurrenceValue['Frequency'] = profilesItem.recurrence.frequency !== null && profilesItem.recurrence.frequency !== undefined ? profilesItem.recurrence.frequency.toString() : 'None';
            }
            
            if (profilesItem.recurrence.schedule !== null && profilesItem.recurrence.schedule !== undefined) {
              var scheduleValue = {};
              recurrenceValue['Schedule'] = scheduleValue;
              
              if (profilesItem.recurrence.schedule.timeZone !== null && profilesItem.recurrence.schedule.timeZone !== undefined) {
                scheduleValue['TimeZone'] = profilesItem.recurrence.schedule.timeZone;
              }
              
              if (profilesItem.recurrence.schedule.days !== null && profilesItem.recurrence.schedule.days !== undefined) {
                var daysArray = [];
                for (var loweredIndex3 = 0; loweredIndex3 < profilesItem.recurrence.schedule.days.length; loweredIndex3 = loweredIndex3 + 1) {
                  var daysItem = profilesItem.recurrence.schedule.days[loweredIndex3];
                  daysArray.push(daysItem);
                }
                scheduleValue['Days'] = daysArray;
              }
              
              if (profilesItem.recurrence.schedule.hours !== null && profilesItem.recurrence.schedule.hours !== undefined) {
                var hoursArray = [];
                for (var loweredIndex4 = 0; loweredIndex4 < profilesItem.recurrence.schedule.hours.length; loweredIndex4 = loweredIndex4 + 1) {
                  var hoursItem = profilesItem.recurrence.schedule.hours[loweredIndex4];
                  hoursArray.push(hoursItem);
                }
                scheduleValue['Hours'] = hoursArray;
              }
              
              if (profilesItem.recurrence.schedule.minutes !== null && profilesItem.recurrence.schedule.minutes !== undefined) {
                var minutesArray = [];
                for (var loweredIndex5 = 0; loweredIndex5 < profilesItem.recurrence.schedule.minutes.length; loweredIndex5 = loweredIndex5 + 1) {
                  var minutesItem = profilesItem.recurrence.schedule.minutes[loweredIndex5];
                  minutesArray.push(minutesItem);
                }
                scheduleValue['Minutes'] = minutesArray;
              }
            }
          }
        }
        autoscaleSettingCreateOrUpdateParametersValue['Profiles'] = profilesArray;
      }
      
      if (parameters.setting.enabled !== null && parameters.setting.enabled !== undefined) {
        autoscaleSettingCreateOrUpdateParametersValue['Enabled'] = parameters.setting.enabled;
      }
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 201) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * 
   * @param {string} resourceId The resource ID.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SettingOperations.prototype.deleteMethod = function(resourceId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceId === null || resourceId === undefined) {
      return callback(new Error('resourceId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/monitoring/autoscalesettings';
    var queryParameters = [];
    queryParameters.push('resourceId=' + encodeURIComponent(resourceId));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.headers['x-ms-version'] = '2013-10-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * 
   * @param {string} resourceId The resource ID.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SettingOperations.prototype.get = function(resourceId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceId === null || resourceId === undefined) {
      return callback(new Error('resourceId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/monitoring/autoscalesettings';
    var queryParameters = [];
    queryParameters.push('resourceId=' + encodeURIComponent(resourceId));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.headers['x-ms-version'] = '2013-10-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var settingInstance = { profiles: [] };
          result.setting = settingInstance;
          
          var profilesArray = responseDoc['Profiles'];
          if (profilesArray !== null && profilesArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < profilesArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var profilesValue = profilesArray[loweredIndex1];
              var autoscaleProfileInstance = { rules: [] };
              settingInstance.profiles.push(autoscaleProfileInstance);
              
              var nameValue = profilesValue['Name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                autoscaleProfileInstance.name = nameInstance;
              }
              
              var capacityValue = profilesValue['Capacity'];
              if (capacityValue !== null && capacityValue !== undefined) {
                var capacityInstance = {};
                autoscaleProfileInstance.capacity = capacityInstance;
                
                var minimumValue = capacityValue['Minimum'];
                if (minimumValue !== null && minimumValue !== undefined) {
                  var minimumInstance = minimumValue;
                  capacityInstance.minimum = minimumInstance;
                }
                
                var maximumValue = capacityValue['Maximum'];
                if (maximumValue !== null && maximumValue !== undefined) {
                  var maximumInstance = maximumValue;
                  capacityInstance.maximum = maximumInstance;
                }
                
                var defaultValue = capacityValue['Default'];
                if (defaultValue !== null && defaultValue !== undefined) {
                  var defaultInstance = defaultValue;
                  capacityInstance.default = defaultInstance;
                }
              }
              
              var rulesArray = profilesValue['Rules'];
              if (rulesArray !== null && rulesArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < rulesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var rulesValue = rulesArray[loweredIndex2];
                  var scaleRuleInstance = {};
                  autoscaleProfileInstance.rules.push(scaleRuleInstance);
                  
                  var metricTriggerValue = rulesValue['MetricTrigger'];
                  if (metricTriggerValue !== null && metricTriggerValue !== undefined) {
                    var metricTriggerInstance = {};
                    scaleRuleInstance.metricTrigger = metricTriggerInstance;
                    
                    var metricNameValue = metricTriggerValue['MetricName'];
                    if (metricNameValue !== null && metricNameValue !== undefined) {
                      var metricNameInstance = metricNameValue;
                      metricTriggerInstance.metricName = metricNameInstance;
                    }
                    
                    var metricNamespaceValue = metricTriggerValue['MetricNamespace'];
                    if (metricNamespaceValue !== null && metricNamespaceValue !== undefined) {
                      var metricNamespaceInstance = metricNamespaceValue;
                      metricTriggerInstance.metricNamespace = metricNamespaceInstance;
                    }
                    
                    var metricSourceValue = metricTriggerValue['MetricSource'];
                    if (metricSourceValue !== null && metricSourceValue !== undefined) {
                      var metricSourceInstance = metricSourceValue;
                      metricTriggerInstance.metricSource = metricSourceInstance;
                    }
                    
                    var timeGrainValue = metricTriggerValue['TimeGrain'];
                    if (timeGrainValue !== null && timeGrainValue !== undefined) {
                      var timeGrainInstance = moment.duration(timeGrainValue);
                      metricTriggerInstance.timeGrain = timeGrainInstance;
                    }
                    
                    var statisticValue = metricTriggerValue['Statistic'];
                    if (statisticValue !== null && statisticValue !== undefined) {
                      var statisticInstance = statisticValue;
                      metricTriggerInstance.statistic = statisticInstance;
                    }
                    
                    var timeWindowValue = metricTriggerValue['TimeWindow'];
                    if (timeWindowValue !== null && timeWindowValue !== undefined) {
                      var timeWindowInstance = moment.duration(timeWindowValue);
                      metricTriggerInstance.timeWindow = timeWindowInstance;
                    }
                    
                    var timeAggregationValue = metricTriggerValue['TimeAggregation'];
                    if (timeAggregationValue !== null && timeAggregationValue !== undefined) {
                      var timeAggregationInstance = timeAggregationValue;
                      metricTriggerInstance.timeAggregation = timeAggregationInstance;
                    }
                    
                    var operatorValue = metricTriggerValue['Operator'];
                    if (operatorValue !== null && operatorValue !== undefined) {
                      var operatorInstance = operatorValue;
                      metricTriggerInstance.operator = operatorInstance;
                    }
                    
                    var thresholdValue = metricTriggerValue['Threshold'];
                    if (thresholdValue !== null && thresholdValue !== undefined) {
                      var thresholdInstance = thresholdValue;
                      metricTriggerInstance.threshold = thresholdInstance;
                    }
                  }
                  
                  var scaleActionValue = rulesValue['ScaleAction'];
                  if (scaleActionValue !== null && scaleActionValue !== undefined) {
                    var scaleActionInstance = {};
                    scaleRuleInstance.scaleAction = scaleActionInstance;
                    
                    var directionValue = scaleActionValue['Direction'];
                    if (directionValue !== null && directionValue !== undefined) {
                      var directionInstance = directionValue;
                      scaleActionInstance.direction = directionInstance;
                    }
                    
                    var typeValue = scaleActionValue['Type'];
                    if (typeValue !== null && typeValue !== undefined) {
                      var typeInstance = typeValue;
                      scaleActionInstance.type = typeInstance;
                    }
                    
                    var valueValue = scaleActionValue['Value'];
                    if (valueValue !== null && valueValue !== undefined) {
                      var valueInstance = valueValue;
                      scaleActionInstance.value = valueInstance;
                    }
                    
                    var cooldownValue = scaleActionValue['Cooldown'];
                    if (cooldownValue !== null && cooldownValue !== undefined) {
                      var cooldownInstance = moment.duration(cooldownValue);
                      scaleActionInstance.cooldown = cooldownInstance;
                    }
                  }
                }
              }
              
              var fixedDateValue = profilesValue['FixedDate'];
              if (fixedDateValue !== null && fixedDateValue !== undefined) {
                var fixedDateInstance = {};
                autoscaleProfileInstance.fixedDate = fixedDateInstance;
                
                var timeZoneValue = fixedDateValue['TimeZone'];
                if (timeZoneValue !== null && timeZoneValue !== undefined) {
                  var timeZoneInstance = timeZoneValue;
                  fixedDateInstance.timeZone = timeZoneInstance;
                }
                
                var startValue = fixedDateValue['Start'];
                if (startValue !== null && startValue !== undefined) {
                  var startInstance = startValue;
                  fixedDateInstance.start = startInstance;
                }
                
                var endValue = fixedDateValue['End'];
                if (endValue !== null && endValue !== undefined) {
                  var endInstance = endValue;
                  fixedDateInstance.end = endInstance;
                }
              }
              
              var recurrenceValue = profilesValue['Recurrence'];
              if (recurrenceValue !== null && recurrenceValue !== undefined) {
                var recurrenceInstance = {};
                autoscaleProfileInstance.recurrence = recurrenceInstance;
                
                var frequencyValue = recurrenceValue['Frequency'];
                if (frequencyValue !== null && frequencyValue !== undefined) {
                  var frequencyInstance = frequencyValue;
                  recurrenceInstance.frequency = frequencyInstance;
                }
                
                var scheduleValue = recurrenceValue['Schedule'];
                if (scheduleValue !== null && scheduleValue !== undefined) {
                  var scheduleInstance = { days: [], hours: [], minutes: [] };
                  recurrenceInstance.schedule = scheduleInstance;
                  
                  var timeZoneValue2 = scheduleValue['TimeZone'];
                  if (timeZoneValue2 !== null && timeZoneValue2 !== undefined) {
                    var timeZoneInstance2 = timeZoneValue2;
                    scheduleInstance.timeZone = timeZoneInstance2;
                  }
                  
                  var daysArray = scheduleValue['Days'];
                  if (daysArray !== null && daysArray !== undefined) {
                    for (var loweredIndex3 = 0; loweredIndex3 < daysArray.length; loweredIndex3 = loweredIndex3 + 1) {
                      var daysValue = daysArray[loweredIndex3];
                      scheduleInstance.days.push(daysValue);
                    }
                  }
                  
                  var hoursArray = scheduleValue['Hours'];
                  if (hoursArray !== null && hoursArray !== undefined) {
                    for (var loweredIndex4 = 0; loweredIndex4 < hoursArray.length; loweredIndex4 = loweredIndex4 + 1) {
                      var hoursValue = hoursArray[loweredIndex4];
                      scheduleInstance.hours.push(hoursValue);
                    }
                  }
                  
                  var minutesArray = scheduleValue['Minutes'];
                  if (minutesArray !== null && minutesArray !== undefined) {
                    for (var loweredIndex5 = 0; loweredIndex5 < minutesArray.length; loweredIndex5 = loweredIndex5 + 1) {
                      var minutesValue = minutesArray[loweredIndex5];
                      scheduleInstance.minutes.push(minutesValue);
                    }
                  }
                }
              }
            }
          }
          
          var enabledValue = responseDoc['Enabled'];
          if (enabledValue !== null && enabledValue !== undefined) {
            var enabledInstance = enabledValue;
            settingInstance.enabled = enabledInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return SettingOperations;
})();
