text: /* 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 azureCommon = require('azure-common');
  var Service = azureCommon.Service;
  var WebResource = azureCommon.WebResource;
  
  var SubscriptionClient = ( /** @lends SubscriptionClient */ function() {
    /**
     * @class
     * Initializes a new instance of the SubscriptionClient class.
     * @constructor
     * 
     * @param {CloudCredentials} credentials Credentials used to authenticate
     * requests.
     * 
     * @param {string} [baseUri] Gets the URI used as the base for all cloud
     * service requests.
     * 
     * @param {Array} filters
     */
    function SubscriptionClient(credentials, baseUri, filters) {
      if (credentials === null || credentials === undefined) {
        throw new Error('credentials cannot be null.');
      }
      
      SubscriptionClient['super_'].call(this, credentials, filters);
      
      this.credentials = credentials;
      this.baseUri = baseUri;
      if (this.baseUri === null || this.baseUri === undefined) {
        this.baseUri = 'https://management.azure.com/';
      }
      if (this.apiVersion === null || this.apiVersion === undefined) {
        this.apiVersion = '2014-04-01-preview';
      }
      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
       * [SubscriptionOperations](-SubscriptionOperations.html) object.
       * @type {object}
       */
      this.subscriptions = new SubscriptionOperations(this);
      /**
       * Provides an instance of the [TenantOperations](-TenantOperations.html)
       * object.
       * @type {object}
       */
      this.tenants = new TenantOperations(this);
    }
    
    util.inherits(SubscriptionClient, Service);
    
    
    return SubscriptionClient;
  })();
  exports.SubscriptionClient = SubscriptionClient;
  
  var SubscriptionOperations = ( /** @lends SubscriptionOperations */ function() {
    /**
     * @class
     * Operations for managing subscriptions.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [SubscriptionClient] {@link
     * SubscriptionClient~SubscriptionClient}.
     * See [subscriptions] {@link
     * SubscriptionClient~SubscriptionClient#subscriptions}.
     * Initializes a new instance of the SubscriptionOperations class.
     * @constructor
     * 
     * @param {SubscriptionClient} client Reference to the service client.
     */
    function SubscriptionOperations(client) {
      this.client = client;
    }
    
    /**
     * Gets details about particular subscription.
     * 
     * @param {string} subscriptionId Id of the subscription.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SubscriptionOperations.prototype.get = function(subscriptionId, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (subscriptionId === null || subscriptionId === undefined) {
        return callback(new Error('subscriptionId cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      url2 = url2 + encodeURIComponent(subscriptionId);
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01-preview');
      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['Content-Type'] = 'application/json; charset=utf-8';
      
      // 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 subscriptionInstance = {};
            result.subscription = subscriptionInstance;
            
            var idValue = responseDoc['id'];
            if (idValue !== null && idValue !== undefined) {
              var idInstance = idValue;
              subscriptionInstance.id = idInstance;
            }
            
            var subscriptionIdValue = responseDoc['subscriptionId'];
            if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
              var subscriptionIdInstance = subscriptionIdValue;
              subscriptionInstance.subscriptionId = subscriptionIdInstance;
            }
            
            var displayNameValue = responseDoc['displayName'];
            if (displayNameValue !== null && displayNameValue !== undefined) {
              var displayNameInstance = displayNameValue;
              subscriptionInstance.displayName = displayNameInstance;
            }
            
            var stateValue = responseDoc['state'];
            if (stateValue !== null && stateValue !== undefined) {
              var stateInstance = stateValue;
              subscriptionInstance.state = stateInstance;
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Gets a list of the subscriptionIds.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SubscriptionOperations.prototype.list = function(callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01-preview');
      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['Content-Type'] = 'application/json; charset=utf-8';
      
      // 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 = { subscriptions: [] };
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
            var valueArray = responseDoc['value'];
            if (valueArray !== null && valueArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var valueValue = valueArray[loweredIndex1];
                var subscriptionInstance = {};
                result.subscriptions.push(subscriptionInstance);
                
                var idValue = valueValue['id'];
                if (idValue !== null && idValue !== undefined) {
                  var idInstance = idValue;
                  subscriptionInstance.id = idInstance;
                }
                
                var subscriptionIdValue = valueValue['subscriptionId'];
                if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
                  var subscriptionIdInstance = subscriptionIdValue;
                  subscriptionInstance.subscriptionId = subscriptionIdInstance;
                }
                
                var displayNameValue = valueValue['displayName'];
                if (displayNameValue !== null && displayNameValue !== undefined) {
                  var displayNameInstance = displayNameValue;
                  subscriptionInstance.displayName = displayNameInstance;
                }
                
                var stateValue = valueValue['state'];
                if (stateValue !== null && stateValue !== undefined) {
                  var stateInstance = stateValue;
                  subscriptionInstance.state = stateInstance;
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return SubscriptionOperations;
  })();
  
  var TenantOperations = ( /** @lends TenantOperations */ function() {
    /**
     * @class
     * Operations for managing tenants.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [SubscriptionClient] {@link
     * SubscriptionClient~SubscriptionClient}.
     * See [tenants] {@link SubscriptionClient~SubscriptionClient#tenants}.
     * Initializes a new instance of the TenantOperations class.
     * @constructor
     * 
     * @param {SubscriptionClient} client Reference to the service client.
     */
    function TenantOperations(client) {
      this.client = client;
    }
    
    /**
     * Gets a list of the tenantIds.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    TenantOperations.prototype.list = function(callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/tenants';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01-preview');
      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['Content-Type'] = 'application/json; charset=utf-8';
      
      // 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 = { tenantIds: [] };
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
            var valueArray = responseDoc['value'];
            if (valueArray !== null && valueArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var valueValue = valueArray[loweredIndex1];
                var tenantIdDescriptionInstance = {};
                result.tenantIds.push(tenantIdDescriptionInstance);
                
                var idValue = valueValue['id'];
                if (idValue !== null && idValue !== undefined) {
                  var idInstance = idValue;
                  tenantIdDescriptionInstance.id = idInstance;
                }
                
                var tenantIdValue = valueValue['tenantId'];
                if (tenantIdValue !== null && tenantIdValue !== undefined) {
                  var tenantIdInstance = tenantIdValue;
                  tenantIdDescriptionInstance.tenantId = tenantIdInstance;
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return TenantOperations;
  })();
  