/*!
 * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
 */

import {
  WebexPlugin
} from '@webex/webex-core';

/**
 * @typedef {Object} AttachmentActionObject
 * @property {string} id - (server generated) Unique identifier for the attachment action
 * @property {string} messageId - The ID of the message in which attachment action is to be performed
 * @property {string} type - The type of attachment action eg., submit
 * @property {Object} inputs - The inputs for form fields in attachment message
 * @property {string} personId - (server generated) The ID for the author of the attachment action
 * @property {string} roomId - (server generated) The ID for the room of the message
 * @property {isoDate} created - (server generated) The date and time that the message was created
 */

const AttachmentActions = WebexPlugin.extend({
  /**
   * Initializer used to generate AttachmentActions
   * as a plugin wrapped around the provided arguments.
   * @see WebexPlugin.initialize
   * @param  {...any} args
   * @returns {undefined}
   */
  initialize(...args) {
    Reflect.apply(WebexPlugin.prototype.initialize, this, args);
  },

  /**
   * Post a new attachment action for a message with attachment.
   * @instance
   * @memberof AttachmentActions
   * @param {AttachmentActionObject} attachmentAction
   * @returns {Promise<AttachmentActionObject>}
   * @example
   * webex.rooms.create({title: 'Create Message Example'})
   *   .then(function(room) {
   *     return webex.messages.create({
   *       text: 'Howdy!',
   *       roomId: room.id,
   *       attachments:[ {
   *          contentType: 'application/vnd.microsoft.card.adaptive',
   *         content: {
   *           type: 'AdaptiveCard',
   *           version: '1.0',
   *           body: [
   *            {
   *             type: 'TextBlock',
   *             text: '',
   *             size: 'large'
   *             },
   *           {
   *             type: 'TextBlock',
   *             text: 'Adaptive Cards',
   *             separation: 'none'
   *           }
   *           {
   *           type: 'Input.Date',
   *           id: 'dueDate'
   *           }
   *       ],
   *     actions: [
   *         {
   *             type: 'Action.Submit',
   *             title: 'Due Date'
   *         }
   *     ]
   *   }
   *  }]
   *     });
   *   })
   *   .then(function(message) {
   *    return webex.attachmentActions.create({
   *      type: 'submit',
   *      messageId: message.id,
   *      inputs:{
   *        dueDate: '26/06/1995'
   *      }
   *    })
   *    .then(function(attachmentAction)){
   *      var assert = require('assert');
   *      assert(attachmentAction.id);
   *      assert(attachmentAction.type);
   *      assert(attachmentAction.personId);
   *      assert(attachmentAction.inputs);
   *      assert(attachmentAction.messageId);
   *      assert(attachmentAction.roomId);
   *      assert(attachmentAction.created);
   *      return 'success';
   *     }
   *   });
   *   // => success
   */
  create(attachmentAction) {
    return this.request({
      method: 'POST',
      service: 'hydra',
      resource: 'attachment/actions',
      body: attachmentAction
    })
      .then((res) => res.body);
  },

  /**
   * Returns a single attachment action.
   * @instance
   * @memberof AttachmentActions
   * @param {string} attachmentAction
   * @returns {Promise<AttachmentActionObject>}
   * @example
   * var attachmentAction;
   * webex.rooms.create({title: 'Get Message Example'})
   *   .then(function(room) {
   *     return webex.messages.create({
   *       text: 'Howdy!',
   *       roomId: room.id,
   *       attachments:[ {
   *          contentType: 'application/vnd.microsoft.card.adaptive',
   *         content: {
   *           type: 'AdaptiveCard',
   *           version: '1.0',
   *           body: [
   *            {
   *             type: 'TextBlock',
   *             text: '',
   *             size: 'large'
   *             },
   *           {
   *             type: 'TextBlock',
   *             text: 'Adaptive Cards',
   *             separation: 'none'
   *           },
   *           {
   *           type: 'Input.Date',
   *           id: 'dueDate'
   *           }
   *       ],
   *     actions: [
   *         {
   *             type: 'Action.Submit',
   *             title: 'Due Date'
   *         }
   *     ]
   *   }
   *  }]
   *     });
   *   })
   *   .then(function(message) {
   *     return webex.attachmentActions.create({
   *      type: 'submit',
   *      messageId: message.id,
   *      inputs:{
   *        dueDate: '26/06/1995'
   *      });
   *   })
   *   .then(function(attachmentAction) {
   *     return webex.attachmentActions.get(attachmentAction.id)
   *   })
   *    .then(function(attachmentAction){
   *        var assert = require('assert');
   *        assert.deepEqual(attachmentAction, attachmentAction);
   *        return 'success';
   *      })
   *   // => success
   */
  get(attachmentAction) {
    const id = attachmentAction.id || attachmentAction;

    return this.request({
      service: 'hydra',
      resource: `attachment/actions/${id}`
    })
      .then((res) => res.body.items || res.body);
  }
});

export default AttachmentActions;

@@ -959,16 +959,30 @@
 uments.%0A
+   * @private%0A
    * @se

add private jsdoc