text: /*
   * Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
   * the MIT License. See LICENSE in the project root for license information.
   * <autogenerated> This file was generated using AutoRest. </autogenerated>
   */
  
  'use strict';
  
  var util = require('util');
  var msRest = require('ms-rest');
  var WebResource = msRest.WebResource;
  
  /**
   * @class
   * UserTopics
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the SocialPlusClient.
   * Initializes a new instance of the UserTopics class.
   * @constructor
   *
   * @param {SocialPlusClient} client Reference to the service client.
   */
  function UserTopics(client) {
    this.client = client;
  }
  
  /**
   * @summary Get user topics sorted by creation time
   *
   * @param {string} userHandle Handle of queried user
   * 
   * @param {string} authorization Format is: "Scheme CredentialsList". Possible
   * values are:
   * 
   * - Anon AK=AppKey
   * 
   * - SocialPlus TK=SessionToken
   * 
   * - Facebook AK=AppKey|TK=AccessToken
   * 
   * - Google AK=AppKey|TK=AccessToken
   * 
   * - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken
   * 
   * - Microsoft AK=AppKey|TK=AccessToken
   * 
   * - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {string} [options.cursor] Current read cursor
   * 
   * @param {number} [options.limit] Number of items to return
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} callback
   *
   * @returns {function} callback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object.
   *                      See {@link FeedResponseTopicView} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  UserTopics.prototype.getTopics = function (userHandle, authorization, options, callback) {
    var client = this.client;
    if(!callback && typeof options === 'function') {
      callback = options;
      options = null;
    }
    if (!callback) {
      throw new Error('callback cannot be null.');
    }
    var cursor = (options && options.cursor !== undefined) ? options.cursor : undefined;
    var limit = (options && options.limit !== undefined) ? options.limit : undefined;
    // Validate
    try {
      if (userHandle === null || userHandle === undefined || typeof userHandle.valueOf() !== 'string') {
        throw new Error('userHandle cannot be null or undefined and it must be of type string.');
      }
      if (cursor !== null && cursor !== undefined && typeof cursor.valueOf() !== 'string') {
        throw new Error('cursor must be of type string.');
      }
      if (limit !== null && limit !== undefined && typeof limit !== 'number') {
        throw new Error('limit must be of type number.');
      }
      if (authorization === null || authorization === undefined || typeof authorization.valueOf() !== 'string') {
        throw new Error('authorization cannot be null or undefined and it must be of type string.');
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    var requestUrl = this.client.baseUri +
                     '//v0.7/users/{userHandle}/topics';
    requestUrl = requestUrl.replace('{userHandle}', encodeURIComponent(userHandle));
    var queryParameters = [];
    if (cursor !== null && cursor !== undefined) {
      queryParameters.push('cursor=' + encodeURIComponent(cursor));
    }
    if (limit !== null && limit !== undefined) {
      queryParameters.push('limit=' + encodeURIComponent(limit.toString()));
    }
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    if (authorization !== undefined && authorization !== null) {
      httpRequest.headers['Authorization'] = authorization;
    }
    if(options) {
      for(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 400 && statusCode !== 401 && statusCode !== 404 && statusCode !== 500) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var parsedErrorResponse;
        try {
          parsedErrorResponse = JSON.parse(responseBody);
          if (parsedErrorResponse) {
            if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
            if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
            if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
      // Deserialize Response
      if (statusCode === 200) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['FeedResponseTopicView']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  /**
   * @summary Get user topics sorted by popularity
   *
   * @param {string} userHandle Handle of queried user
   * 
   * @param {string} authorization Format is: "Scheme CredentialsList". Possible
   * values are:
   * 
   * - Anon AK=AppKey
   * 
   * - SocialPlus TK=SessionToken
   * 
   * - Facebook AK=AppKey|TK=AccessToken
   * 
   * - Google AK=AppKey|TK=AccessToken
   * 
   * - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken
   * 
   * - Microsoft AK=AppKey|TK=AccessToken
   * 
   * - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {number} [options.cursor] Current read cursor
   * 
   * @param {number} [options.limit] Number of items to return
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} callback
   *
   * @returns {function} callback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object.
   *                      See {@link FeedResponseTopicView} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  UserTopics.prototype.getPopularTopics = function (userHandle, authorization, options, callback) {
    var client = this.client;
    if(!callback && typeof options === 'function') {
      callback = options;
      options = null;
    }
    if (!callback) {
      throw new Error('callback cannot be null.');
    }
    var cursor = (options && options.cursor !== undefined) ? options.cursor : undefined;
    var limit = (options && options.limit !== undefined) ? options.limit : undefined;
    // Validate
    try {
      if (userHandle === null || userHandle === undefined || typeof userHandle.valueOf() !== 'string') {
        throw new Error('userHandle cannot be null or undefined and it must be of type string.');
      }
      if (cursor !== null && cursor !== undefined && typeof cursor !== 'number') {
        throw new Error('cursor must be of type number.');
      }
      if (limit !== null && limit !== undefined && typeof limit !== 'number') {
        throw new Error('limit must be of type number.');
      }
      if (authorization === null || authorization === undefined || typeof authorization.valueOf() !== 'string') {
        throw new Error('authorization cannot be null or undefined and it must be of type string.');
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    var requestUrl = this.client.baseUri +
                     '//v0.7/users/{userHandle}/topics/popular';
    requestUrl = requestUrl.replace('{userHandle}', encodeURIComponent(userHandle));
    var queryParameters = [];
    if (cursor !== null && cursor !== undefined) {
      queryParameters.push('cursor=' + encodeURIComponent(cursor.toString()));
    }
    if (limit !== null && limit !== undefined) {
      queryParameters.push('limit=' + encodeURIComponent(limit.toString()));
    }
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    if (authorization !== undefined && authorization !== null) {
      httpRequest.headers['Authorization'] = authorization;
    }
    if(options) {
      for(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 400 && statusCode !== 401 && statusCode !== 404 && statusCode !== 500) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var parsedErrorResponse;
        try {
          parsedErrorResponse = JSON.parse(responseBody);
          if (parsedErrorResponse) {
            if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
            if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
            if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
      // Deserialize Response
      if (statusCode === 200) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['FeedResponseTopicView']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  
  module.exports = UserTopics;
  