"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");

var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");

_Object$defineProperty(exports, "__esModule", {
  value: true
});

exports["default"] = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));

require("regenerator-runtime/runtime");

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));

/**
 * @file Represents Salesforce QuickAction
 * @author Shinichi Tomita <shinichi.tomita@gmail.com>
 */

/**
 * type definitions
 */

/**
 * A class for quick action
 */
var QuickAction =
/*#__PURE__*/
function () {
  /**
   *
   */
  function QuickAction(conn, path) {
    (0, _classCallCheck2["default"])(this, QuickAction);
    (0, _defineProperty2["default"])(this, "_conn", void 0);
    (0, _defineProperty2["default"])(this, "_path", void 0);
    this._conn = conn;
    this._path = path;
  }
  /**
   * Describe the action's information (including layout, etc.)
   */


  (0, _createClass2["default"])(QuickAction, [{
    key: "describe",
    value: function describe() {
      var url, body;
      return _regenerator["default"].async(function describe$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              url = "".concat(this._path, "/describe");
              _context.next = 3;
              return _regenerator["default"].awrap(this._conn.request(url));

            case 3:
              body = _context.sent;
              return _context.abrupt("return", body);

            case 5:
            case "end":
              return _context.stop();
          }
        }
      }, null, this);
    }
    /**
     * Retrieve default field values in the action (for given record, if specified)
     */

  }, {
    key: "defaultValues",
    value: function defaultValues(contextId) {
      var url, body;
      return _regenerator["default"].async(function defaultValues$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              url = "".concat(this._path, "/defaultValues");

              if (contextId) {
                url += "/".concat(contextId);
              }

              _context2.next = 4;
              return _regenerator["default"].awrap(this._conn.request(url));

            case 4:
              body = _context2.sent;
              return _context2.abrupt("return", body);

            case 6:
            case "end":
              return _context2.stop();
          }
        }
      }, null, this);
    }
    /**
     * Execute the action for given context Id and record information
     */

  }, {
    key: "execute",
    value: function execute(contextId, record) {
      var requestBody, resBody;
      return _regenerator["default"].async(function execute$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              requestBody = {
                contextId: contextId,
                record: record
              };
              _context3.next = 3;
              return _regenerator["default"].awrap(this._conn.requestPost(this._path, requestBody));

            case 3:
              resBody = _context3.sent;
              return _context3.abrupt("return", resBody);

            case 5:
            case "end":
              return _context3.stop();
          }
        }
      }, null, this);
    }
  }]);
  return QuickAction;
}();

exports["default"] = QuickAction;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9xdWljay1hY3Rpb24udHMiXSwibmFtZXMiOlsiUXVpY2tBY3Rpb24iLCJjb25uIiwicGF0aCIsIl9jb25uIiwiX3BhdGgiLCJ1cmwiLCJyZXF1ZXN0IiwiYm9keSIsImNvbnRleHRJZCIsInJlY29yZCIsInJlcXVlc3RCb2R5IiwicmVxdWVzdFBvc3QiLCJyZXNCb2R5Il0sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUE7Ozs7O0FBWUE7Ozs7QUFjQTs7O0lBR3FCQSxXOzs7QUFJbkI7OztBQUdBLHVCQUFZQyxJQUFaLEVBQWlDQyxJQUFqQyxFQUErQztBQUFBO0FBQUE7QUFBQTtBQUM3QyxTQUFLQyxLQUFMLEdBQWFGLElBQWI7QUFDQSxTQUFLRyxLQUFMLEdBQWFGLElBQWI7QUFDRDtBQUVEOzs7Ozs7Ozs7Ozs7O0FBSVFHLGNBQUFBLEcsYUFBUyxLQUFLRCxLOzttREFDRCxLQUFLRCxLQUFMLENBQVdHLE9BQVgsQ0FBbUJELEdBQW5CLEM7OztBQUFiRSxjQUFBQSxJOytDQUNDQSxJOzs7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