text: /**!
   *
   * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
   * @private
   */
  
  import {SparkPlugin, Page} from '@ciscospark/spark-core';
  import {base64} from '@ciscospark/common';
  
  /**
   * @typedef {Object} Types~Person
   * @property {uuid} id - Unique identifier for the person
   * @property {Array<email>} emails - Email addresses of the person
   * @property {string} displayName - Display name of the person
   * @property {isoDate} created - The date and time that the person was created
   */
  
  /**
   * @class
   * @extends SparkPlugin
   */
  const People = SparkPlugin.extend({
    namespace: `People`,
  
    /**
     * Returns a single person by ID
     * @instance
     * @memberof People
     * @param {Types~Person|uuid} person
     * @returns {Promise<Types~Person>}
     * @example
     * ciscospark.rooms.create({title: 'Get Person Example'})
     *   .then(function(room) {
     *     return ciscospark.memberships.create({
     *       personEmail: 'alice@example.com',
     *       roomId: room.id
     *     });
     *   })
     *   .then(function(membership) {
     *     return ciscospark.people.get(membership.personId);
     *   })
     *   .then(function(alice) {
     *     var assert = require('assert');
     *     assert(alice.id);
     *     assert(Array.isArray(alice.emails));
     *     assert.equal(alice.emails.filter(function(email) {
     *       return email === 'alice@example.com';
     *     }).length, 1);
     *     assert(alice.displayName);
     *     assert(alice.created);
     *     return 'success';
     *   });
     *   // => success
     */
    get(person) {
      if (!person) {
        return Promise.reject(new Error(`A person with an id is required`));
      }
      const id = person.personId || person.id || person;
      return this.request({
        service: `hydra`,
        resource: `people/${id}`
      })
        .then((res) => res.body);
    },
  
    /**
     * Returns a list of people
     * @instance
     * @memberof People
     * @param {Object} options
     * @param {email} options.email - Returns people with an email that contains this string
     * @param {string} options.displayName - Returns people with a name that contains this string
     * @returns {Promise<Page<Types~Person>>}
     * @example
     * var room;
     * ciscospark.rooms.create({title: 'List People Example'})
     *   .then(function(r) {
     *     room = r;
     *     return ciscospark.memberships.create({
     *       personEmail: 'alice@example.com',
     *       roomId: room.id
     *     });
     *   })
     *   .then(function() {
     *     return ciscospark.memberships.create({
     *       personEmail: 'bob@example.com',
     *       roomId: room.id
     *     });
     *   })
     *   .then(function() {
     *     return ciscospark.people.list({email: 'alice@example.com'});
     *   })
     *   .then(function(people) {
     *     var assert = require('assert');
     *     assert.equal(people.length, 1);
     *     var person = people.items[0];
     *     assert(person.id);
     *     assert(Array.isArray(person.emails));
     *     assert(person.displayName);
     *     assert(person.created);
     *     return 'success';
     *   });
     *   // => success
     */
    list(options) {
      return this.request({
        service: `hydra`,
        resource: `people`,
        qs: options
      })
        .then((res) => new Page(res, this.spark));
    },
  
    /**
     * Convertis a uuid to a hydra id without a network dip.
     * @param {string} id
     * @private
     * @returns {string}
     */
    inferPersonIdFromUuid(id) {
      return base64.encode(`ciscospark://us/PEOPLE/${id}`);
    }
  });
  
  export default People;
  