/* 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 _ = require('underscore');
var azureCommon = require('azure-common');
var Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;

var GalleryClient = ( /** @lends GalleryClient */ function() {
  /**
   * @class
   * Initializes a new instance of the GalleryClient 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 GalleryClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    GalleryClient['super_'].call(this, credentials, filters);
    
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = 'https://gallery.azure.com/';
    }
    if (this.apiVersion === null || this.apiVersion === undefined) {
      this.apiVersion = '2015-04-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 [ItemOperations](-ItemOperations.html)
     * object.
     * @type {object}
     */
    this.items = new ItemOperations(this);
  }
  
  util.inherits(GalleryClient, Service);
  
  
  return GalleryClient;
})();
exports.GalleryClient = GalleryClient;

var ItemOperations = ( /** @lends ItemOperations */ function() {
  /**
   * @class
   * Operations for working with gallery items.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [GalleryClient] {@link GalleryClient~GalleryClient}.
   * See [items] {@link GalleryClient~GalleryClient#items}.
   * Initializes a new instance of the ItemOperations class.
   * @constructor
   * 
   * @param {GalleryClient} client Reference to the service client.
   */
  function ItemOperations(client) {
    this.client = client;
  }
  
  /**
   * Gets a gallery items.
   * 
   * @param {string} [itemIdentity] Gallery item identity.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ItemOperations.prototype.get = function(itemIdentity, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/Microsoft.Gallery/galleryitems/';
    if (itemIdentity !== null && itemIdentity !== undefined) {
      url2 = url2 + encodeURIComponent(itemIdentity);
    }
    var queryParameters = [];
    queryParameters.push('api-version=2015-04-01');
    queryParameters.push('includePreview=true');
    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 itemInstance = { artifacts: [], categories: [], filters: [], iconFileUris: {}, links: [], metadata: {}, products: [], properties: {}, screenshotUris: [] };
          result.item = itemInstance;
          
          var identityValue = responseDoc['identity'];
          if (identityValue !== null && identityValue !== undefined) {
            var identityInstance = identityValue;
            itemInstance.identity = identityInstance;
          }
          
          var itemNameValue = responseDoc['itemName'];
          if (itemNameValue !== null && itemNameValue !== undefined) {
            var itemNameInstance = itemNameValue;
            itemInstance.name = itemNameInstance;
          }
          
          var itemDisplayNameValue = responseDoc['itemDisplayName'];
          if (itemDisplayNameValue !== null && itemDisplayNameValue !== undefined) {
            var itemDisplayNameInstance = itemDisplayNameValue;
            itemInstance.displayName = itemDisplayNameInstance;
          }
          
          var publisherValue = responseDoc['publisher'];
          if (publisherValue !== null && publisherValue !== undefined) {
            var publisherInstance = publisherValue;
            itemInstance.publisher = publisherInstance;
          }
          
          var publisherDisplayNameValue = responseDoc['publisherDisplayName'];
          if (publisherDisplayNameValue !== null && publisherDisplayNameValue !== undefined) {
            var publisherDisplayNameInstance = publisherDisplayNameValue;
            itemInstance.publisherDisplayName = publisherDisplayNameInstance;
          }
          
          var versionValue = responseDoc['version'];
          if (versionValue !== null && versionValue !== undefined) {
            var versionInstance = versionValue;
            itemInstance.version = versionInstance;
          }
          
          var summaryValue = responseDoc['summary'];
          if (summaryValue !== null && summaryValue !== undefined) {
            var summaryInstance = summaryValue;
            itemInstance.summary = summaryInstance;
          }
          
          var longSummaryValue = responseDoc['longSummary'];
          if (longSummaryValue !== null && longSummaryValue !== undefined) {
            var longSummaryInstance = longSummaryValue;
            itemInstance.longSummary = longSummaryInstance;
          }
          
          var descriptionValue = responseDoc['description'];
          if (descriptionValue !== null && descriptionValue !== undefined) {
            var descriptionInstance = descriptionValue;
            itemInstance.description = descriptionInstance;
          }
          
          var marketingMaterialValue = responseDoc['marketingMaterial'];
          if (marketingMaterialValue !== null && marketingMaterialValue !== undefined) {
            var marketingMaterialInstance = {};
            itemInstance.marketingMaterial = marketingMaterialInstance;
            
            var pathValue = marketingMaterialValue['path'];
            if (pathValue !== null && pathValue !== undefined) {
              var pathInstance = pathValue;
              marketingMaterialInstance.path = pathInstance;
            }
          }
          
          var screenshotUrisArray = responseDoc['screenshotUris'];
          if (screenshotUrisArray !== null && screenshotUrisArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < screenshotUrisArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var screenshotUrisValue = screenshotUrisArray[loweredIndex1];
              itemInstance.screenshotUris.push(screenshotUrisValue);
            }
          }
          
          var iconFileUrisSequenceElement = responseDoc['iconFileUris'];
          if (iconFileUrisSequenceElement !== null && iconFileUrisSequenceElement !== undefined) {
            for (var property in iconFileUrisSequenceElement) {
              var iconFileUrisKey = property;
              var iconFileUrisValue = iconFileUrisSequenceElement[property];
              itemInstance.iconFileUris[iconFileUrisKey] = iconFileUrisValue;
            }
          }
          
          var linksArray = responseDoc['links'];
          if (linksArray !== null && linksArray !== undefined) {
            for (var loweredIndex2 = 0; loweredIndex2 < linksArray.length; loweredIndex2 = loweredIndex2 + 1) {
              var linksValue = linksArray[loweredIndex2];
              var linkInstance = {};
              itemInstance.links.push(linkInstance);
              
              var idValue = linksValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                linkInstance.identifier = idInstance;
              }
              
              var displayNameValue = linksValue['displayName'];
              if (displayNameValue !== null && displayNameValue !== undefined) {
                var displayNameInstance = displayNameValue;
                linkInstance.displayName = displayNameInstance;
              }
              
              var uriValue = linksValue['uri'];
              if (uriValue !== null && uriValue !== undefined) {
                var uriInstance = uriValue;
                linkInstance.uri = uriInstance;
              }
            }
          }
          
          var categoryIdsArray = responseDoc['categoryIds'];
          if (categoryIdsArray !== null && categoryIdsArray !== undefined) {
            for (var loweredIndex3 = 0; loweredIndex3 < categoryIdsArray.length; loweredIndex3 = loweredIndex3 + 1) {
              var categoryIdsValue = categoryIdsArray[loweredIndex3];
              itemInstance.categories.push(categoryIdsValue);
            }
          }
          
          var propertiesSequenceElement = responseDoc['properties'];
          if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
            for (var property2 in propertiesSequenceElement) {
              var propertiesKey = property2;
              var propertiesValue = propertiesSequenceElement[property2];
              itemInstance.properties[propertiesKey] = propertiesValue;
            }
          }
          
          var metadataSequenceElement = responseDoc['metadata'];
          if (metadataSequenceElement !== null && metadataSequenceElement !== undefined) {
            for (var property3 in metadataSequenceElement) {
              var metadataKey = property3;
              var metadataValue = metadataSequenceElement[property3];
              itemInstance.metadata[metadataKey] = metadataValue;
            }
          }
          
          var artifactsArray = responseDoc['artifacts'];
          if (artifactsArray !== null && artifactsArray !== undefined) {
            for (var loweredIndex4 = 0; loweredIndex4 < artifactsArray.length; loweredIndex4 = loweredIndex4 + 1) {
              var artifactsValue = artifactsArray[loweredIndex4];
              var artifactInstance = {};
              itemInstance.artifacts.push(artifactInstance);
              
              var nameValue = artifactsValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                artifactInstance.name = nameInstance;
              }
              
              var uriValue2 = artifactsValue['uri'];
              if (uriValue2 !== null && uriValue2 !== undefined) {
                var uriInstance2 = uriValue2;
                artifactInstance.uri = uriInstance2;
              }
              
              var typeValue = artifactsValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                artifactInstance.type = typeInstance;
              }
            }
          }
          
          var filtersArray = responseDoc['filters'];
          if (filtersArray !== null && filtersArray !== undefined) {
            for (var loweredIndex5 = 0; loweredIndex5 < filtersArray.length; loweredIndex5 = loweredIndex5 + 1) {
              var filtersValue = filtersArray[loweredIndex5];
              var filterInstance = {};
              itemInstance.filters.push(filterInstance);
              
              var typeValue2 = filtersValue['type'];
              if (typeValue2 !== null && typeValue2 !== undefined) {
                var typeInstance2 = typeValue2;
                filterInstance.type = typeInstance2;
              }
              
              var valueValue = filtersValue['value'];
              if (valueValue !== null && valueValue !== undefined) {
                var valueInstance = valueValue;
                filterInstance.value = valueInstance;
              }
            }
          }
          
          var productsArray = responseDoc['products'];
          if (productsArray !== null && productsArray !== undefined) {
            for (var loweredIndex6 = 0; loweredIndex6 < productsArray.length; loweredIndex6 = loweredIndex6 + 1) {
              var productsValue = productsArray[loweredIndex6];
              var productInstance = {};
              itemInstance.products.push(productInstance);
              
              var displayNameValue2 = productsValue['displayName'];
              if (displayNameValue2 !== null && displayNameValue2 !== undefined) {
                var displayNameInstance2 = displayNameValue2;
                productInstance.displayName = displayNameInstance2;
              }
              
              var publisherDisplayNameValue2 = productsValue['publisherDisplayName'];
              if (publisherDisplayNameValue2 !== null && publisherDisplayNameValue2 !== undefined) {
                var publisherDisplayNameInstance2 = publisherDisplayNameValue2;
                productInstance.publisherDisplayName = publisherDisplayNameInstance2;
              }
              
              var legalTermsUriValue = productsValue['legalTermsUri'];
              if (legalTermsUriValue !== null && legalTermsUriValue !== undefined) {
                var legalTermsUriInstance = legalTermsUriValue;
                productInstance.legalTermsUri = legalTermsUriInstance;
              }
              
              var privacyPolicyUriValue = productsValue['privacyPolicyUri'];
              if (privacyPolicyUriValue !== null && privacyPolicyUriValue !== undefined) {
                var privacyPolicyUriInstance = privacyPolicyUriValue;
                productInstance.privacyPolicyUri = privacyPolicyUriInstance;
              }
              
              var pricingDetailsUriValue = productsValue['pricingDetailsUri'];
              if (pricingDetailsUriValue !== null && pricingDetailsUriValue !== undefined) {
                var pricingDetailsUriInstance = pricingDetailsUriValue;
                productInstance.pricingDetailsUri = pricingDetailsUriInstance;
              }
              
              var offerDetailsValue = productsValue['offerDetails'];
              if (offerDetailsValue !== null && offerDetailsValue !== undefined) {
                var offerDetailsInstance = { plans: [] };
                productInstance.offerDetails = offerDetailsInstance;
                
                var offerIdValue = offerDetailsValue['offerId'];
                if (offerIdValue !== null && offerIdValue !== undefined) {
                  var offerIdInstance = offerIdValue;
                  offerDetailsInstance.offerIdentifier = offerIdInstance;
                }
                
                var publisherIdValue = offerDetailsValue['publisherId'];
                if (publisherIdValue !== null && publisherIdValue !== undefined) {
                  var publisherIdInstance = publisherIdValue;
                  offerDetailsInstance.publisherIdentifier = publisherIdInstance;
                }
                
                var plansArray = offerDetailsValue['plans'];
                if (plansArray !== null && plansArray !== undefined) {
                  for (var loweredIndex7 = 0; loweredIndex7 < plansArray.length; loweredIndex7 = loweredIndex7 + 1) {
                    var plansValue = plansArray[loweredIndex7];
                    var planInstance = {};
                    offerDetailsInstance.plans.push(planInstance);
                    
                    var planIdValue = plansValue['planId'];
                    if (planIdValue !== null && planIdValue !== undefined) {
                      var planIdInstance = planIdValue;
                      planInstance.planIdentifier = planIdInstance;
                    }
                    
                    var displayNameValue3 = plansValue['displayName'];
                    if (displayNameValue3 !== null && displayNameValue3 !== undefined) {
                      var displayNameInstance3 = displayNameValue3;
                      planInstance.displayName = displayNameInstance3;
                    }
                    
                    var summaryValue2 = plansValue['summary'];
                    if (summaryValue2 !== null && summaryValue2 !== undefined) {
                      var summaryInstance2 = summaryValue2;
                      planInstance.summary = summaryInstance2;
                    }
                    
                    var descriptionValue2 = plansValue['description'];
                    if (descriptionValue2 !== null && descriptionValue2 !== undefined) {
                      var descriptionInstance2 = descriptionValue2;
                      planInstance.description = descriptionInstance2;
                    }
                  }
                }
              }
            }
          }
          
          var uiDefinitionUriValue = responseDoc['uiDefinitionUri'];
          if (uiDefinitionUriValue !== null && uiDefinitionUriValue !== undefined) {
            var uiDefinitionUriInstance = uiDefinitionUriValue;
            itemInstance.uiDefinitionUri = uiDefinitionUriInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets collection of gallery items.
   * 
   * @param {ItemListParameters} [parametersOrCallback] Query parameters. If
   * null is passed returns all gallery items.
   * 
   * @param {string} [parametersOrCallback.filter] Gets or sets OData filter.
   * Optional.
   * 
   * @param {number} [parametersOrCallback.top] Number of items to return.
   * Optional.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ItemOperations.prototype.list = function(parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/Microsoft.Gallery/galleryitems';
    var queryParameters = [];
    queryParameters.push('api-version=2015-04-01');
    queryParameters.push('includePreview=true');
    var odataFilter = [];
    if (parameters !== null && parameters !== undefined && parameters.filter !== null && parameters.filter !== undefined) {
      odataFilter.push(encodeURIComponent(parameters.filter));
    }
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (parameters !== null && parameters !== undefined && parameters.top !== null && parameters.top !== undefined) {
      queryParameters.push('$top=' + encodeURIComponent(parameters.top.toString()));
    }
    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 = { items: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var itemsArray = responseDoc;
          if (itemsArray !== null && itemsArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < itemsArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var itemsValue = itemsArray[loweredIndex1];
              var galleryItemInstance = { artifacts: [], categories: [], filters: [], iconFileUris: {}, links: [], metadata: {}, products: [], properties: {}, screenshotUris: [] };
              result.items.push(galleryItemInstance);
              
              var identityValue = itemsValue['identity'];
              if (identityValue !== null && identityValue !== undefined) {
                var identityInstance = identityValue;
                galleryItemInstance.identity = identityInstance;
              }
              
              var itemNameValue = itemsValue['itemName'];
              if (itemNameValue !== null && itemNameValue !== undefined) {
                var itemNameInstance = itemNameValue;
                galleryItemInstance.name = itemNameInstance;
              }
              
              var itemDisplayNameValue = itemsValue['itemDisplayName'];
              if (itemDisplayNameValue !== null && itemDisplayNameValue !== undefined) {
                var itemDisplayNameInstance = itemDisplayNameValue;
                galleryItemInstance.displayName = itemDisplayNameInstance;
              }
              
              var publisherValue = itemsValue['publisher'];
              if (publisherValue !== null && publisherValue !== undefined) {
                var publisherInstance = publisherValue;
                galleryItemInstance.publisher = publisherInstance;
              }
              
              var publisherDisplayNameValue = itemsValue['publisherDisplayName'];
              if (publisherDisplayNameValue !== null && publisherDisplayNameValue !== undefined) {
                var publisherDisplayNameInstance = publisherDisplayNameValue;
                galleryItemInstance.publisherDisplayName = publisherDisplayNameInstance;
              }
              
              var versionValue = itemsValue['version'];
              if (versionValue !== null && versionValue !== undefined) {
                var versionInstance = versionValue;
                galleryItemInstance.version = versionInstance;
              }
              
              var summaryValue = itemsValue['summary'];
              if (summaryValue !== null && summaryValue !== undefined) {
                var summaryInstance = summaryValue;
                galleryItemInstance.summary = summaryInstance;
              }
              
              var longSummaryValue = itemsValue['longSummary'];
              if (longSummaryValue !== null && longSummaryValue !== undefined) {
                var longSummaryInstance = longSummaryValue;
                galleryItemInstance.longSummary = longSummaryInstance;
              }
              
              var descriptionValue = itemsValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                galleryItemInstance.description = descriptionInstance;
              }
              
              var marketingMaterialValue = itemsValue['marketingMaterial'];
              if (marketingMaterialValue !== null && marketingMaterialValue !== undefined) {
                var marketingMaterialInstance = {};
                galleryItemInstance.marketingMaterial = marketingMaterialInstance;
                
                var pathValue = marketingMaterialValue['path'];
                if (pathValue !== null && pathValue !== undefined) {
                  var pathInstance = pathValue;
                  marketingMaterialInstance.path = pathInstance;
                }
              }
              
              var screenshotUrisArray = itemsValue['screenshotUris'];
              if (screenshotUrisArray !== null && screenshotUrisArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < screenshotUrisArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var screenshotUrisValue = screenshotUrisArray[loweredIndex2];
                  galleryItemInstance.screenshotUris.push(screenshotUrisValue);
                }
              }
              
              var iconFileUrisSequenceElement = itemsValue['iconFileUris'];
              if (iconFileUrisSequenceElement !== null && iconFileUrisSequenceElement !== undefined) {
                for (var property in iconFileUrisSequenceElement) {
                  var iconFileUrisKey = property;
                  var iconFileUrisValue = iconFileUrisSequenceElement[property];
                  galleryItemInstance.iconFileUris[iconFileUrisKey] = iconFileUrisValue;
                }
              }
              
              var linksArray = itemsValue['links'];
              if (linksArray !== null && linksArray !== undefined) {
                for (var loweredIndex3 = 0; loweredIndex3 < linksArray.length; loweredIndex3 = loweredIndex3 + 1) {
                  var linksValue = linksArray[loweredIndex3];
                  var linkInstance = {};
                  galleryItemInstance.links.push(linkInstance);
                  
                  var idValue = linksValue['id'];
                  if (idValue !== null && idValue !== undefined) {
                    var idInstance = idValue;
                    linkInstance.identifier = idInstance;
                  }
                  
                  var displayNameValue = linksValue['displayName'];
                  if (displayNameValue !== null && displayNameValue !== undefined) {
                    var displayNameInstance = displayNameValue;
                    linkInstance.displayName = displayNameInstance;
                  }
                  
                  var uriValue = linksValue['uri'];
                  if (uriValue !== null && uriValue !== undefined) {
                    var uriInstance = uriValue;
                    linkInstance.uri = uriInstance;
                  }
                }
              }
              
              var categoryIdsArray = itemsValue['categoryIds'];
              if (categoryIdsArray !== null && categoryIdsArray !== undefined) {
                for (var loweredIndex4 = 0; loweredIndex4 < categoryIdsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                  var categoryIdsValue = categoryIdsArray[loweredIndex4];
                  galleryItemInstance.categories.push(categoryIdsValue);
                }
              }
              
              var propertiesSequenceElement = itemsValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property2 in propertiesSequenceElement) {
                  var propertiesKey = property2;
                  var propertiesValue = propertiesSequenceElement[property2];
                  galleryItemInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var metadataSequenceElement = itemsValue['metadata'];
              if (metadataSequenceElement !== null && metadataSequenceElement !== undefined) {
                for (var property3 in metadataSequenceElement) {
                  var metadataKey = property3;
                  var metadataValue = metadataSequenceElement[property3];
                  galleryItemInstance.metadata[metadataKey] = metadataValue;
                }
              }
              
              var artifactsArray = itemsValue['artifacts'];
              if (artifactsArray !== null && artifactsArray !== undefined) {
                for (var loweredIndex5 = 0; loweredIndex5 < artifactsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                  var artifactsValue = artifactsArray[loweredIndex5];
                  var artifactInstance = {};
                  galleryItemInstance.artifacts.push(artifactInstance);
                  
                  var nameValue = artifactsValue['name'];
                  if (nameValue !== null && nameValue !== undefined) {
                    var nameInstance = nameValue;
                    artifactInstance.name = nameInstance;
                  }
                  
                  var uriValue2 = artifactsValue['uri'];
                  if (uriValue2 !== null && uriValue2 !== undefined) {
                    var uriInstance2 = uriValue2;
                    artifactInstance.uri = uriInstance2;
                  }
                  
                  var typeValue = artifactsValue['type'];
                  if (typeValue !== null && typeValue !== undefined) {
                    var typeInstance = typeValue;
                    artifactInstance.type = typeInstance;
                  }
                }
              }
              
              var filtersArray = itemsValue['filters'];
              if (filtersArray !== null && filtersArray !== undefined) {
                for (var loweredIndex6 = 0; loweredIndex6 < filtersArray.length; loweredIndex6 = loweredIndex6 + 1) {
                  var filtersValue = filtersArray[loweredIndex6];
                  var filterInstance = {};
                  galleryItemInstance.filters.push(filterInstance);
                  
                  var typeValue2 = filtersValue['type'];
                  if (typeValue2 !== null && typeValue2 !== undefined) {
                    var typeInstance2 = typeValue2;
                    filterInstance.type = typeInstance2;
                  }
                  
                  var valueValue = filtersValue['value'];
                  if (valueValue !== null && valueValue !== undefined) {
                    var valueInstance = valueValue;
                    filterInstance.value = valueInstance;
                  }
                }
              }
              
              var productsArray = itemsValue['products'];
              if (productsArray !== null && productsArray !== undefined) {
                for (var loweredIndex7 = 0; loweredIndex7 < productsArray.length; loweredIndex7 = loweredIndex7 + 1) {
                  var productsValue = productsArray[loweredIndex7];
                  var productInstance = {};
                  galleryItemInstance.products.push(productInstance);
                  
                  var displayNameValue2 = productsValue['displayName'];
                  if (displayNameValue2 !== null && displayNameValue2 !== undefined) {
                    var displayNameInstance2 = displayNameValue2;
                    productInstance.displayName = displayNameInstance2;
                  }
                  
                  var publisherDisplayNameValue2 = productsValue['publisherDisplayName'];
                  if (publisherDisplayNameValue2 !== null && publisherDisplayNameValue2 !== undefined) {
                    var publisherDisplayNameInstance2 = publisherDisplayNameValue2;
                    productInstance.publisherDisplayName = publisherDisplayNameInstance2;
                  }
                  
                  var legalTermsUriValue = productsValue['legalTermsUri'];
                  if (legalTermsUriValue !== null && legalTermsUriValue !== undefined) {
                    var legalTermsUriInstance = legalTermsUriValue;
                    productInstance.legalTermsUri = legalTermsUriInstance;
                  }
                  
                  var privacyPolicyUriValue = productsValue['privacyPolicyUri'];
                  if (privacyPolicyUriValue !== null && privacyPolicyUriValue !== undefined) {
                    var privacyPolicyUriInstance = privacyPolicyUriValue;
                    productInstance.privacyPolicyUri = privacyPolicyUriInstance;
                  }
                  
                  var pricingDetailsUriValue = productsValue['pricingDetailsUri'];
                  if (pricingDetailsUriValue !== null && pricingDetailsUriValue !== undefined) {
                    var pricingDetailsUriInstance = pricingDetailsUriValue;
                    productInstance.pricingDetailsUri = pricingDetailsUriInstance;
                  }
                  
                  var offerDetailsValue = productsValue['offerDetails'];
                  if (offerDetailsValue !== null && offerDetailsValue !== undefined) {
                    var offerDetailsInstance = { plans: [] };
                    productInstance.offerDetails = offerDetailsInstance;
                    
                    var offerIdValue = offerDetailsValue['offerId'];
                    if (offerIdValue !== null && offerIdValue !== undefined) {
                      var offerIdInstance = offerIdValue;
                      offerDetailsInstance.offerIdentifier = offerIdInstance;
                    }
                    
                    var publisherIdValue = offerDetailsValue['publisherId'];
                    if (publisherIdValue !== null && publisherIdValue !== undefined) {
                      var publisherIdInstance = publisherIdValue;
                      offerDetailsInstance.publisherIdentifier = publisherIdInstance;
                    }
                    
                    var plansArray = offerDetailsValue['plans'];
                    if (plansArray !== null && plansArray !== undefined) {
                      for (var loweredIndex8 = 0; loweredIndex8 < plansArray.length; loweredIndex8 = loweredIndex8 + 1) {
                        var plansValue = plansArray[loweredIndex8];
                        var planInstance = {};
                        offerDetailsInstance.plans.push(planInstance);
                        
                        var planIdValue = plansValue['planId'];
                        if (planIdValue !== null && planIdValue !== undefined) {
                          var planIdInstance = planIdValue;
                          planInstance.planIdentifier = planIdInstance;
                        }
                        
                        var displayNameValue3 = plansValue['displayName'];
                        if (displayNameValue3 !== null && displayNameValue3 !== undefined) {
                          var displayNameInstance3 = displayNameValue3;
                          planInstance.displayName = displayNameInstance3;
                        }
                        
                        var summaryValue2 = plansValue['summary'];
                        if (summaryValue2 !== null && summaryValue2 !== undefined) {
                          var summaryInstance2 = summaryValue2;
                          planInstance.summary = summaryInstance2;
                        }
                        
                        var descriptionValue2 = plansValue['description'];
                        if (descriptionValue2 !== null && descriptionValue2 !== undefined) {
                          var descriptionInstance2 = descriptionValue2;
                          planInstance.description = descriptionInstance2;
                        }
                      }
                    }
                  }
                }
              }
              
              var uiDefinitionUriValue = itemsValue['uiDefinitionUri'];
              if (uiDefinitionUriValue !== null && uiDefinitionUriValue !== undefined) {
                var uiDefinitionUriInstance = uiDefinitionUriValue;
                galleryItemInstance.uiDefinitionUri = uiDefinitionUriInstance;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ItemOperations;
})();
